jdk8-》allMatch、anyMatch、max、min函數


allMatch函數:

檢查是否匹配所有元素,只有全部符合才返回true
boolean flag = list.stream().allMatch(obj->obj.length()>5);
 
anyMatch函數
檢查是否⾄少匹配⼀個元素,只要有一個符合就返回true
boolean flag = list.stream().anyMatch(obj->obj.length()>18);
 
max函數
list.stream().max(Comparator.comparingInt(Student::getAge));
 
min函數
Optional<Student> optional = list.stream().min((s1, s2)->Integer.compare(s1.getAge(),s2.getAge()));


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM