I’m iterating an ArrayList of clients named clientList that contains clients from the class Client (user,pass)
ArrayList<Client> clientList= new ArrayList<Client>();
Here’s the iteration. I want to stop the iteration if it founds a given user (user) and if the password (pass) matches:
for (Client c : clientList) {
userA = c.getUser();
if (userA.equals(user)) {
passA = c.getPassword();
if (passA.equals(pass)) {
loginOK = true;
found= true;
}
I was trying the following while (found == false) but it’s get stucked if it doesnt find an user on the ArrayList:
while (found == false) { /
for (Client c : clientList) {
userA = c.getUser();
if (userA.equals(user)) {
passA = c.getPassword();
if (passA.equals(pass)) {
loginOK = true;
found= true;
}
}
}
}
I’d write it this way:
My guess is that you didn’t override equals and hashCode in your
Clienteclass or it’s not correct.