T
-流中的元素的类型
S
-流实施
BaseStream
类型
public interface BaseStream<T,S extends BaseStream<T,S>> extends AutoCloseable
Stream
和
IntStream
聚合运算,计算的红色小部件的权重的总和:
int sum = widgets.stream()
.filter(w -> w.getColor() == RED)
.mapToInt(w -> w.getWeight())
.sum();
看到
Stream
为流,额外的规范
java.util.stream包文档类文件流操作,流管道,和并行性,决定着一切的流类型的行为。
Stream
,
IntStream
,
LongStream
,
DoubleStream
,
java.util.stream
Modifier and Type | Method and Description |
---|---|
void |
close()
关闭此流,导致该流管道的所有关闭处理程序被调用。
|
boolean |
isParallel()
返回此流是否要执行一个终端操作,将并行执行。
|
Iterator<T> |
iterator()
返回此流的元素的迭代器。
|
S |
onClose(Runnable closeHandler)
返回一个额外的关闭处理程序的等效流。
|
S |
parallel()
返回一个并行的等效流。
|
S |
sequential()
返回一个连续的等效流。
|
Spliterator<T> |
spliterator()
返回一个对该流的元素spliterator。
|
S |
unordered()
返回一个等效流,
unordered。
|
Iterator<T> iterator()
这是一个terminal operation。
Spliterator<T> spliterator()
这是一个terminal operation。
boolean isParallel()
true
流并行执行,如果执行
S sequential()
S parallel()
S onClose(Runnable closeHandler)
close()
方法称为对流,并被执行的顺序被加入。所有关闭处理程序都会运行,即使早期关闭处理程序抛出异常。如果关闭处理程序引发异常,首先抛出的异常将传递到
close()
来电,任何剩余的例外添加到例外,抑制异常(除非剩余一个例外是例外,第一个例外,同时由于例外不能抑制自己。)可能返回自身。
closeHandler
-任务时执行流关闭
void close()
close
接口
AutoCloseable
AutoCloseable.close()
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.