Home > OS >  Java String Contains Not Printing [closed]
Java String Contains Not Printing [closed]

Time:10-07

Can someone explain to me why the phrase in my if statement is not printing?

    String[] words = "or successful;".toLowerCase().split(" ");
    for (int i = 0; i < words.length; i  ) {
        String word = words[i];
        
        if (word.contains(";")) {
            System.out.println("got it");
        }
    }

CodePudding user response:

You should have copied "or successful;" from some place (maybe a PDF or similar). It looks like a ; but it is not the same and the one you have in the line if (word.contains(";")) {.

Either retype "or successful;" or copy the semicolon to the if condition.

  • Related