让我们说我上课了
public class Data{
public int k;
public int l;
public Data(int k, int l){
this.k = k;
this.l = l;
}
public boolean equals(Date m){
if(this.k == m.k && this.l = m.l)
return true;
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
我向ArrayList添加了一些Data对象:
ArrayList<Data> holder = new ArrayList<Data>;
Data one = new Data(0,0);
Data two = new Data(0,4);
Data three = new Data(0,5);
Run Code Online (Sandbox Code Playgroud)
为什么indexOf找不到这个?:
holder.indexOf(new Data(0,4)); //returns -1
Run Code Online (Sandbox Code Playgroud)
indexOf是否比自己遍历整个数组列表更好?或者我错过了什么.