【发布时间】:2012-11-23 10:40:42
【问题描述】:
我有一个名为Person 的课程。它有以下attributes;它有 2 个属性,ID 和 Telephone。一个人可以有多个电话,所以你可能会在下面看到有多个 ID 的人。
public ArrayList<Person> all(){
p = new ArrayList<Person>();
p.add(new Person(1,266763));
p.add(new Person(1, 358643));
p.add(new Person(2, 4667763));
return p;
}
还有一个名为PersonDB 的类。它会有一个名为findPersonWithTheTelephoneNumber(int telephone)的方法。
public void findPersonWithTheTelephoneNumber(int telephone) {
Person pp = new Person();
ArrayList<Person> personList = pp.all();
// Now i want to find the Person object that will match the telephone number of these list of personList.
}
personList,有 3-4 个 Person 对象。我需要搜索 PersonArrayList 并找到与 Person 对象匹配的对象。我怎样才能做到这一点?
注意:我试过personList.contains()。但这不起作用。
【问题讨论】:
标签: java class object arraylist