import java.util.Comparator;
import java.util.PriorityQueue;
public class TestPQ {
public static void main(String[] args){
Comparator com
non terminal operation is not doing any processing. Its the terminal operation only, who start the processing of all the non terminal operation and then finally terminal operation.
The map() method itself is intermediate and does not enforce the consumption of a Stream
so it's a very bad idea to put side effects there.
In this case, you should use the dedicated forEach() method:
queue.stream()
.forEach(s -> System.out.println("queue: " + s));
You don't have any terminal operation consuming your stream. So nothing happens. map()
is an intermediate operation, which is not supposed to have side effects. What your code should be is
queue.stream().forEach(s-> {
System.out.println("queue: "+ s);
});