且构网

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

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

更新时间:2023-10-05 16:12: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));