小编Yut*_*uto的帖子

Stream.of() 和 stream() 的区别

我试图弄清楚stream.of()和之间的差异在哪里stream(),我遇到了这个。谁能向我解释为什么第一个不起作用?

//Given: List<Integer> transactions

transactions.add(1);

transactions.add(2);

//This won't compile,

Stream.of(transactions).filter(x->x<3).collect(Collectors.toList());

// while this one does fine:

transactions.stream().filter(x->x<3).collect(Collectors.toList()); 
Run Code Online (Sandbox Code Playgroud)

java java-stream

-5
推荐指数
1
解决办法
68
查看次数

标签 统计

java ×1

java-stream ×1