Java ArrayList IndexOf - Finding Object Index

后端 未结 4 1386
独厮守ぢ
独厮守ぢ 2020-12-05 19:56

Lets say I have a class

public class Data{
    public int k;
    public int l;
    public Data(int k, int l){
      this.k = k; 
      this.l = l;
    }
             


        
4条回答
  •  被撕碎了的回忆
    2020-12-05 20:24

    By convention you want to override hashcode also when you override equals

    You will most probably find that the indexOf uses the hashcode method to match the object not the equals

    If you use eclise to edit you code - eclipse will generate a good equals and hashcode method for you from the "source" menu.

提交回复
热议问题