filter(Predicate p) 过滤流
limit(int) 截取流,使元素不超过指定数量
slip(int n) 跳过元素,返回一个扔掉前n个元素的流,假设长度不足n,就返回空流
distinct() 根据equals方法去重
map(Function f) 转换类型
faltmap(Function f) 转换类型 可以将流中所有对象的流提取出来,合成一个新的流
List<Double[]> data = Arrays.asList(new Double[]{12.3,23.4},new Double[]{22.3,33.4});
List<Double> collect = data.stream().flatMap(a -> Arrays.stream(a)).collect(Collectors.toList()); //{12.3,23.4,22.3,33.4}
sorted() 产生一个新流,其中按自然排序排序
sorted(Comparator com) 产生一个新流,自定义排序
allMacth(Predicate p) 检查是否匹配所有
List<Integer> list=Arrays.asList(1,2,3,4);
boolean b = list.stream().allMatch(item -> item > 1); //false 因为1不大于 1
anyMacth(Predicate p) 匹配至少一个元素
List<Integer> list=Arrays.asList(1,2,3,4);
boolean b = list.stream().anyMatch(item -> item == 1); //true
noneMacth(Predicate p) 匹配没有元素
List<Integer> list=Arrays.asList(1,2,3,4);
boolean b = list.stream().noneMatch(item -> item == 1); //false
findFirst() 返回第一个元素
findAny() 返回当前流任意元素
count() 返回流总个数
max() 返回流中最大值
min() 返回流中最小值
reduce()
List<Integer> list=Arrays.asList(1,2,3,4);
Integer reduce = list.stream().reduce(0, Integer::sum); //求和,0是初始值
//Optional<Integer> reduce = list.stream().reduce(Integer::sum);
//Optional<Integer> reduce = list.stream().reduce((i1,i2)->i1+i2);
collect()