In my application, I have list of values of type String, I am iterating throught it and comparing the values of each to another string and if it is true returning true value else false.
List<String> roleNames = new ArrayList<String>();
roleNames.add("AAA");
roleNames.add("MMM");
for (int i=0 ; i<roleNames.size();i++){
// if(loggedInRole.equals(roleNames.get(i))){
if("AAA".equals(roleNames.get(i))){
enableLink = "true";
}
else {
enableLink = "false";
}
}
In my above code i am expecting the result as true but in the second itertion it returning the result as false. How to reolve this issue?
ArrayListyou can just haveenableLink = roleNames.contains("AAA");