में खोज मैं अपने आईडी नंबर से ArrayList
में किसी ग्राहक को खोजने का सबसे अच्छा तरीका जानने का प्रयास कर रहा हूं। नीचे दिया गया कोड काम नहीं कर रहा है; संकलक मुझे बताता है कि मुझे return
कथन याद आ रहा है।जावा ArrayList
Customer findCustomerByid(int id){
boolean exist=false;
if(this.customers.isEmpty()) {
return null;
}
for(int i=0;i<this.customers.size();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;
}
मुख्य जावा अच्छे व्यवहारों में से एक हमेशा ब्रेसिज़ का उपयोग करना है, भले ही आपके पास –