[英]Java - List of objects. Find object(s) with a certain value in a field
I have two lists of objects. 我有两个对象列表。 The objects in each list are different subclasses of the same class.
每个列表中的对象是同一类的不同子类。
I want to look at objects in list One, check the value of a particular field, and then see if there is/are any objects in list Two that have the same field value. 我想查看列表一中的对象,检查特定字段的值,然后查看列表二中是否存在具有相同字段值的对象。 What would be the best way to do this?
最好的方法是什么?
I believe this is more correct. 我相信这是更正确的。 This is the simplest, easiest solution to implement.
这是最简单,最容易实现的解决方案。
for(TypeA itemA : listA) {
for(TypeB itemB : listB) {
if(itemA.field == ItemB.otherField) {
//Do Whatever
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.