简体   繁体   English

Java-对象列表。 在字段中查找具有特定值的对象

[英]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
        }
    }
}

Jackson (Java):反序列化相同的属性名但返回不同的对象。 其中一个返回 object 和第二个列表<object><div id="text_translate"><p>我有一个这样的 POJO:</p><pre> public class NewClass { String name; @JsonProperty("productType") ProductType productType2005; List&lt;ProductType&gt; productType; }</pre><p> 我想将 json 反序列化为 Pojo。 问题是我的属性名称相同 productType 但我可以期待两种不同的返回类型或数据结构。</p><ol><li> 返回ProductType</li><li> return List&lt;ProductType&gt;因为属性名称相同我如何有效地使用 Jackson 注释来解决它?</li></ol><p> 我使用 rest-assured 进行反序列化,使用 Lombok 进行典型的 getter 和 setter。</p></div></object> - Jackson (Java) : deserialization for the same property name but return different objects. for one it return object and second List<Object>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用对象作为值构成HashMap,而对象又具有它自己的HashMap。 爪哇 - How to make HashMap with an object as value, which again have it's own HashMap of objects. Java 根据对象字段与给定值的绝对差对对象列表进行排序。 (Java) - Sorting a List of Objects based o absolute difference of an Object's field and a given value. (Java) Jackson (Java):反序列化相同的属性名但返回不同的对象。 其中一个返回 object 和第二个列表<object><div id="text_translate"><p>我有一个这样的 POJO:</p><pre> public class NewClass { String name; @JsonProperty("productType") ProductType productType2005; List&lt;ProductType&gt; productType; }</pre><p> 我想将 json 反序列化为 Pojo。 问题是我的属性名称相同 productType 但我可以期待两种不同的返回类型或数据结构。</p><ol><li> 返回ProductType</li><li> return List&lt;ProductType&gt;因为属性名称相同我如何有效地使用 Jackson 注释来解决它?</li></ol><p> 我使用 rest-assured 进行反序列化,使用 Lombok 进行典型的 getter 和 setter。</p></div></object> - Jackson (Java) : deserialization for the same property name but return different objects. for one it return object and second List<Object> 查找列表中包含特定字段的所有对象 - Find all objects in list that contain a certain field Java链接的对象列表。 如何记录每个唯一的对象? - Java Linked List of Objects. How can I keep count of each unique object? 检查对象列表中的字段是否具有特定值? - Checking that a field in a List of Objects has a certain value? Java-根据对象的值对对象进行排序 - Java - sort list of objects based on object's value 我想打印一个对象的varValue及其相关的检查对象。 - I want to print a varValue of an object with it's related review objects. Java,Item对象的链接列表。 如何参考当前项目? - Java, Linked List of Item objects. How to refer to the current item? Java - 将对象数组存储为另一个对象的值并调用该值的字段 - Java - Store array of objects as another object's value and call that value's field
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM