【发布时间】:2019-05-09 13:41:04
【问题描述】:
我创建了一个充满“状态”的数组列表,但在添加状态后无法在列表中找到状态
public class State {
int a;
int b;
int c;
public State(int a,int b,int c) {
super();
this.a = a;
this.b = b;
this.c = c;
}
}
然后在主类中
public class Main {
static ArrayList<State> nodes = new ArrayList<State>();
public static void main(String[] args) {
State randomState = new State(12,0,0);
nodes.add(randomState);
System.out.println(nodes.contains(new State(12,0,0)));
}
}
这将返回 false,但如果我这样做
System.out.println(nodes.contains(randomState));
将返回 true。 任何帮助表示赞赏
【问题讨论】:
标签: java arrays arraylist methods contains