Which statement is true about java.util.stream.Stream?
A. A stream cannot be consumed more than once.
B. The execution mode of streams can be changed during processing.
C. Streams are intended to modify the source data.
D. A parallel stream is always faster than an equivalent sequential stream.
题解
选项 A,串流只能被消耗一次,如果对同一个串流对象再次进行操作,会抛出 IllegalStateException。此为正确答案。
选项 B,这个选项应该是指串流的串行处理模式和平行化处理模式。虽然可以使用 sequential 方法和 parallel 方法来切换模式,但整个串流只会使用最后设置的模式来处理,并不能在处理的过程中改变。
选项 C,串流并不会修改到原始的数据,而是产生新的数据出来。
选项 D,平行化的串流并不总是比串行的串流快,因为多线程会需要消耗额外的资源。
