Java - 对象列表。在字段中查找具有特定值的对象 [英] Java - List of objects. Find object(s) with a certain value in a field

查看:136
本文介绍了Java - 对象列表。在字段中查找具有特定值的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个对象列表。每个列表中的对象是同一个类的不同子类。

I have two lists of objects. The objects in each list are different subclasses of the same class.

我想查看列表一中的对象,检查特定字段的值,然后查看列表2中是否有任何具有相同字符的对象场价值。最好的方法是什么?

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
        }
    }
}

这篇关于Java - 对象列表。在字段中查找具有特定值的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆