0

My intention is to remove the whitespaces and semicolons and if one of the resulting string matches "quit"...I'll print "Yikes!"

I am not sure as to why this is not working.

    String someString = "abc   ;        def   ;quit";
    String[] someArray = someString.split(";");

    for(int i = 0; i < someArray.length; i++) {
        someArray[i] = someArray[i].trim();
        if(someArray[i] == "quit") {
            System.out.println("Yikes!");
        }
    }
devDude
  • 17
  • 3
  • 1
    Note : use `split("\\s*;)` instead of `split(";")` – TheLostMind Oct 17 '16 at 05:50
  • String someString = "abc ; def ;quit"; someString = someString.replace(" ", ""); System.out.println("H:"+someString); String[] someArray = someString.split(";"); for (int i = 0; i < someArray.length; i++) { someArray[i] = someArray[i].trim(); if (someArray[i].equals("quit")) { System.out.println("Yikes!"); } } – Jay Prakash Oct 17 '16 at 05:56
  • Thanks. Does this `split("\\s*;")` mean..one or more spaces and semicolon? – devDude Oct 17 '16 at 05:57

0 Answers0