实际上java8的stream指导思想几乎跟hadoop的Mapreduce如出一辙,
都是基于一个数据流,然后做reduce,最后进行一次聚合的操作,这种模型完美的匹配了多线程
import static静态导入是JDK1.5中的新特性。一般我们导入一个类都用 import com…..ClassName;而静态导入是这样:import static com…..ClassName.*;这里的多了个static,还有就是类名ClassName后面多了个 .* ,意思是导入这个类里的静态方法。当然,也可以只导入某个静态方法,只要把 .* 换成静态方法名就行了。然后在这个类中,就可以直接用方法名调用静态方法,而不必用ClassName.方法名 的方式来调用
下面的例子如果想使用多线程只需要改成
List<Student> stus3 = students.parallelStream().filter(s->s.getScore()>90).collect(toList());
package com.stream;
import java.util.ArrayList;
import java.util.List;
import static java.util.stream.Collectors.toList;
public class TestStream {
public static void main(String args[]){
List<Student> students = new ArrayList<Student>();
students.add(new Student(80));
students.add(new Student(81));
students.add(new Student(82));
students.add(new Student(83));
students.add(new Student(91));
students.add(new Student(92));
Object[] stus = (Object[]) students.stream().filter(s->s.getScore()>90).toArray();
for(Object obj:stus){
Student s = (Student)obj;
System.out.println(s.getScore());
}
Long total = students.stream().filter(s->s.getScore()>90).count();
System.out.println("total:"+total);
List<Integer> stus2 = students.stream().filter(s->s.getScore()>90).map(Student::getScore).collect(toList());
System.out.println(stus2);
List<Student> stus3 = students.stream().filter(s->s.getScore()>90).collect(toList());
System.out.println(stus3);
}
}
class Student{
int score;
Student(int score){
this.score = score;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
}

也可以使用静态的of方法方便的获取一个stream
Long biggerThan1 = Stream.of(“1″,”2″,”3”).filter(s->Integer.parseInt(s)>1).count();
System.out.println(biggerThan1);