Fork/Join框架
延时操作特性
在终结阶段,才会中间操作会进行操作。
public class TestStream{
static class Student{
private String name;
public String getName(){
System.out.println(this.name);
return this.name;
}
public void setName(String name){
this.name = name;
}
pubic Student(String name){
this.name = name;
}
}
public static void main(String[] args) {
List<Student> list = Arrays.asList(new Student("12"),new Student("22"),new Student("13"),new Student("123"));
list.stream().filter(b->b.getName().startWith("1")).foreach(b->{
System.out.println(b.getName());
})
}
}
常用的中间操作(Intermediate)
- map(mapToInt,flagMap等)
- filter
- distinct
- sorted
- peed
- limit
- skip
- parallel
- sequential
- unordered
- concat
常见的终结操作(Terminal)
- forEach
- forEachOrdered
- toArray
- reduce
- collect
- min
- max
- count
- iterator
短路操作(Short-circuiting)
任务执行到中间,就终止stream的操作,也是终结操作。
- anyMatch
- allMatch
- noneMatch
- findFirst
- findAny