I have a string value stored in a variable called userPassword
, which is what I got from the user using scanner. I also have a hashmap like this:
Key | Value |
---|---|
username1 | password1 |
username2 | password2 |
username3 | password3 |
I have a variable userPassword
with value 123
, and also a value in hashmap which is also 123
public class Authentication {
public void verifyLogin(LoginDetailsPojo userLoginDetailsObj, Map<String,String> map){
//Passing a object and hash map as parameters
String userPassword = userLoginDetailsObj.password;
System.out.println(userPassword);//Printing "123"
String mapPassword = map.get(userLoginDetailsObj.userName);
System.out.println(mapPassword); //Printing "123"
if(userPassword.equals(mapPassword))
System.out.println("it is equal");
}
}
}
Even though both the variables (userPassword
and mapPassword
) have the same value 123
, the if
block is not executing