Java Stream.of()和Stream()之间的差异

Java Stream.of()和Stream()之间的差异,java,java-stream,Java,Java 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()); // wh

我试图找出
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()); 
//给定:列出事务
增加(1);
增加(2);
//这不会编译,

Stream.of(transactions).filter(x->xx
Stream.of
创建给定参数的流,并
List.Stream
将列表转换为流

鉴于:

List<Integer> myList = Arrays.asList(1, 2, 3);
List myList=Arrays.asList(1,2,3);
myList.stream()
返回内容为{1,2,3}的


Stream.of(myList)
返回内容为{myList}

Stream
。编译器发出的错误消息对此进行了解释。javadoc也是。Stream.of()的javadoc问?当你给它一个列表时,它会返回什么?请在问题中以文本形式发布代码。而不是作为图像的链接。请使用
code
在代码块中添加你想显示的代码,而不是引用图像URL将它们传递到IDE中所需的数据结构,并查看错误消息告诉你什么,例如
List listStreamOf=Stream.of(transactions).filter(x->x<3).collect(Collectors.toList());
将非常清楚地告诉您一些事情。