Java - TreeSet and hashCode()

前端 未结 4 1319
我在风中等你
我在风中等你 2020-12-03 14:20

I have a quick question about TreeSet collections and hashCode methods. I have a TreeSet and I\'m adding objects to it, before I add an object, I check to see i

4条回答
  •  不思量自难忘°
    2020-12-03 14:39

    You don't need to checked if it is contained, because the insert() basically does the same operation (i.e. searching the proper position) on its way to the insertion point. If the object can't be inserted (i.e., the object is already contained), insert returns false.

提交回复
热议问题