/**
* allMatch()流中的元素必须全部符合筛选条件,才能返回true;
* 否则,返回false。
*/publicclassAllMatchTest{publicstaticvoidmain(String[] args){
List<Integer> list = Arrays.asList(1,2,3,4,5);boolean res = list.stream().allMatch(e -> e >0);
System.out.println(res);}}
anyMatch()
/**
* anyMatch()判断流中是否存在满足条件的元素,任意一个匹配就行
*/publicclassAnyMatchTest{publicstaticvoidmain(String[] args){
List<Integer> list = Arrays.asList(1,2,3,4,5);boolean res = list.stream().anyMatch(e -> e >3);
System.out.println(res);}}
count()
/**
* count()计算流中的元素个数
*/publicclassCountTest{publicstaticvoidmain(String[] args){
List<Integer> list = Arrays.asList(1,2,3,4,5);
Long ans = list.stream().count();
System.out.println(ans);}}
distinct()
/**
* distinct()去重
*/publicclassDistinctTest{publicstaticvoidmain(String[] args){
List<Integer> list = Arrays.asList(1,2,2,3,3,4,5);
list.stream().distinct().forEach(System.out::println);}}
filter()
/**
* filter()过滤流
*/publicclassFilterTest{publicstaticvoidmain(String[] args){
List<Integer> list = Arrays.asList(1,2,3,4,5);
list.stream().filter(i -> i >3).forEach(System.out::println);}}
forEach()
/**
* forEach()增强for循环
*/publicclassForEachTest{publicstaticvoidmain(String[] args){
Random random =newRandom();
random.ints().limit(10).forEach(System.out::println);}}
limit()
/**
* limit()限制输出的元素数量
*/publicclassLimitTest{publicstaticvoidmain(String[] args){
List<Integer> list = Arrays.asList(1,2,3,4,5);
List<Integer> res = list.stream().limit(3).collect(Collectors.toList());
res.stream().forEach(System.out::println);}}
map()
/**
* map()元素映射
*/publicclassMapTest{publicstaticvoidmain(String[] args){
List<Integer> list = Arrays.asList(1,2,3,4,5);
list.stream().map(i ->{return i * i;}).filter(i -> i >3).limit(3).forEach(System.out::println);}}
max()
/**
* max()查找流中的最大值
*/publicclassMaxTest{publicstaticvoidmain(String[] args){
List<Integer> list = Arrays.asList(1,2,3,4,5);
Integer ans = list.stream().max((x,y)-> x - y).get();
System.out.println(ans);}}
min()
/**
* min()找出流中的最小值
*/publicclassMinTest{publicstaticvoidmain(String[] args){
List<Integer> list = Arrays.asList(1,2,3,4,5);
Integer ans = list.stream().min((x,y)-> x - y).get();
System.out.println(ans);}}