其他分享
首页 > 其他分享> > stream使用

stream使用

作者:互联网

String name1 = "子澳";
List<Test111> cityList = new ArrayList<>();
Test111 test111 = new Test111();
test111.setName(name1);
test111.setCode("10101");
cityList.add(test111);
boolean allMatch = cityList.stream().allMatch((e) -> e.getName().equals(name1));
System.out.println("是否匹配所有元素" + allMatch);
boolean anyMatch = cityList.stream().anyMatch((e) -> e.getName().equals(name1));
System.out.println("是否至少匹配所有元素" + anyMatch);
long count = cityList.stream().count();
System.out.println("总数" + count);
Optional<Test111> max = cityList.stream().max(Comparator.comparingDouble(e -> Integer.parseInt(e.getCode())));
System.out.println("返回流中最大值" + max.get());
Optional<Test111> min = cityList.stream().min(Comparator.comparingDouble(e -> Integer.parseInt(e.getCode())));
System.out.println("返回流中最小值" + min.get());
Optional<Test111> filter = cityList.stream().filter((e) -> e.getCode().equals(name1)).findAny();
System.out.println("返回当前流中的任意元素" + filter);
Optional<Test111> sort = cityList.stream().sorted(Comparator.comparingDouble(e -> Integer.parseInt(e.getCode()))).findAny();
System.out.println("返回第一个元素" + sort);

标签:cityList,stream,name1,System,使用,println,out
来源: https://blog.csdn.net/m0_61918283/article/details/122251865