I have an ArrayList which contains data like profId, firstname, lastname, age.
Now I have a lastname and firstname, which gets from user form side. Now I want to compare them with an ArrayList. If both match, I want to retrieve “respective profId”.
e.g arraylist contains data like
profId lastname fistname age
1 roy sam 25
2 ryob arnav 30
Now user will type lastname and firstname as roy and sam respectively. I will get this data by their getter methods.
Now, how should I compare these 2 names with the ArrayList so that I will get the perfect profid of him as:
‘1’.
I am trying to compare by this way.
// existPatList is arraylist patfamily is object of Family from where I will get users value
for(Family p : existPatList) {
System.out.println("Last name" +p.getLastName());
System.out.println("First name"+p.getFirstName());
if(p.getLastName().equalsIgnoreCase(patFamily.getLastName())) {
System.out.println("got it");
}
}
How can I solve this problem?
Use a
&&in yourifcondition with bothfirstNameandlastName.To get
profIdreplace your line:with
I consider here the you
gettersalso has a get method forprofId, that isgetProfId()