Search an ArrayList for a particular Object

前端 未结 6 837
陌清茗
陌清茗 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:41

    //...
    Person foundPerson = null;
    for (Person p : personList){
        if (p.getTelephone() == telephone){
             foundPerson = p; //or simply return it from there
             break;
        }
    }
    

    For implementing hashCode and equals you can observe this tutorial.

提交回复
热议问题