如何在类数组上使用 contains

问题描述 投票:0回答:1
class product
{
 attribute
 setter method
 getter method
}

public class main...
{
 Array List of <Product> products = new ArrayList<Product>();
 boolean checkProduct = products.contains(....); // This is the problem how to use contains on this?
}

检查类数组中的值的方法 contains 对此不起作用。

java arraylist contains
1个回答
0
投票

您需要为您的类产品实现 equals 方法。在 Eclipse 中,您可以通过右键单击编辑器,然后选择“源”>“生成 hashCode() 和 equals()”来完成此操作。

© www.soinside.com 2019 - 2024. All rights reserved.