ArrayDeque<Integer> q = new ArrayDeque<>();
IntStream.range(0, 5).forEach((i) -> {q.addFirst(i);});
System.out.println(q);
IntStream.range(0, 5).forEach((i) -> {
System.out.printf("%d, ", q.pollFirst());
} );
System.out.println(q);
ArrayDeque<Integer> q = new ArrayDeque<>();
IntStream.range(0, 5).forEach((i) -> { q.addFirst(i); });
System.out.println(q);
//[4, 3, 2, 1, 0]
IntStream.range(0, 5).forEach((i) ->{System.out.printf("%d,",q.pollFirst());});
//4, 3, 2, 1, 0,
System.out.println(q); //[]
//q.clear();
###################################
No comments:
Post a Comment