I am able to insert duplicate entries in TreeSet. How to overcome this

后端 未结 3 1580
猫巷女王i
猫巷女王i 2021-01-14 16:15

I have a class called Employee which has employeeName and employeeId as its member variables.I am creating new Employee objects and then adding it

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-14 16:55

    The way you are comparing string is wrong. See How to compare 2 Strings in Java

    (Employee)emp).employeeName== this.employeeName
    

    should be

    (Employee)emp).employeeName.equals(this.employeeName)
    

提交回复
热议问题