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,平行化的串流並不總是比序列的串流快,因為多執行緒會需要消耗額外的資源。
