List<Object1> list1 = userVo.getMstCardTypeVOs();
Object1 object1 = new Object1();
object1.setId(1);
object1.setName("Test");
-- More fields which are not matched with object2
list1.add(object1);
object1 = new Object1();
object1.setId(2);
object1.setName("Test1");
-- More fields which are not matched with object1
list1.add(object1)
List<Object2> list2 = mapMenuProgramRepo.findAll();
Object2 object2 = new Object2();
object2.setId(1);
object2.setName("Test");
list1.add(object2);
object2 = new Object2();
object2.setId(2);
object2.setName("Test1");
list1.add(object2);
我需要檢查相同的ID存在於list1與列表2的引用?操作列表和刪除列表中的數據
我用下面的代碼:
for (Object1 object1 : obj1) {
for (Object2 obj2: obj2) {
if (object2.getId().equals(object1.getId())) {
// removed entry from the list1
// We can removed by using iterator instead of list
}
}
}
什麼更好的方式和優化使用jdk8或7路?從列表1
我見您使用JDK 8它是更有效的JDK7 –
[這](http://stackoverflow.com/questions/31683375/java- 8-lambda-intersection-of-two-lists)可能值得看看 – jrook