Why does Java8 Stream generate nothing?

后端 未结 3 687
萌比男神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:57

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

提交回复
热议问题