我试图找出通过其ID号搜索ArrayList中的客户的最佳方式.以下代码无效;编译器告诉我,我错过了一个return语句.
Customer findCustomerByid(int id){
boolean exist=false;
if(this.customers.isEmpty()) {
return null;
}
for(int i=0;i
if(this.customers.get(i).getId() == id) {
exist=true;
break;
}
if(exist) {
return this.customers.get(id);
} else {
return this.customers.get(id);
}
}
}
//the customer class is something like that
public class Customer {
//attributes
int id;
int tel;
String fname;
String lname;
String resgistrationDate;
}