My Treeset only adds 1 class object

后端 未结 3 1883
你的背包
你的背包 2021-01-27 07:08

I\'m trying to add the below book objects to a TreeSet. However, when I debug the code, it says that the set has a size of 1 and only contains the first object added (book1). Wh

3条回答
  •  春和景丽
    2021-01-27 07:37

    Update your compareTo method based on your requirement. Or at least update as below, it will allow to insert all objects in treeset.

    public int compareTo(Book o) {
    // TODO Auto-generated method stub
    return this.compareTo(o);
    } 
    

提交回复
热议问题