Search an ArrayList for a particular Object

前端 未结 6 843
陌清茗
陌清茗 2021-01-21 07:05

I have a class called Person. It has the following attributes; It has 2 attributes, ID, and Telephone. 1 person can have many

6条回答
  •  面向向阳花
    2021-01-21 07:33

    i tried personList.contains()

    Make sure you override Object.equals() and Object.hashCode() for Person class. But you have to have equality check on telephone number assuming telephone number unique. This would not be a solution but a workaround. Use bellum's answer. Mark it as correct answer.

提交回复
热议问题