I have a code in that I populate a list of words and, after that I run an if-else block see if the list contain certain typed strings, like this:
List<String> list;
String Words;
// <Insert words in the list>
// ...
// List elements as String
for (String Words : list){
// If typed text found, print. (z is search index)
if (Words.contains(Typed.get(z))) {
System.out.println("Typed: " + typed.get(z));
} else if (!Words.contains(Typed.get(z))) {
// If typed text Not found, print error msg.
System.err.println("Not found");
}
}
The else block is being executed even when the word is in the list (In that case both if and else blocks are executed). However, if there's nothing in the list, only the else block is executed.
For example, when I type something that is in the list, Both the "Typed.." And "Not Found" messages are shown.
Is this a problem with my if-else statements or (String.contains)? I have no clue why both statements are being erroneous called.
Thanks in advance
Aucun commentaire:
Enregistrer un commentaire