Why does Java8 Stream generate nothing?

后端 未结 3 660
萌比男神i
萌比男神i 2020-11-30 14:02
import java.util.Comparator;
import java.util.PriorityQueue;


public class TestPQ {
    public static void main(String[] args){
        Comparator com         


        
3条回答
  •  醉梦人生
    2020-11-30 14:56

    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));
    

提交回复
热议问题