且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检查自定义对象列表是否与 Java 8 中的属性具有相同的值

更新时间:2023-10-05 16:16:34

一种方法是获取第一个列表的名称并调用 allMatch 并对其进行检查.

One way is to get the name of the first list and call allMatch and check against that.

String firstName = yourListOfAs.get(0).name;
boolean allSameName = yourListOfAs.stream().allMatch(x -> x.name.equals(firstName));