The code below is mostly self explanatory. However, I am having trouble in two cases:
The
whileloop does not exit even with the command line is left blank.If the input is
test t1thekeyvariable is supposed to be "test" (usingSystem.out.println(key)) does that, but, it still doesn't enter theifcondition for some reason.String[] broken_text = null; String text = ""; BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); while((text = reader.readLine()) != null) { broken_text = text.split(" "); String first_key = broken_text[0]; if (first_key == "test") { //some statements } }
I am not sure why this is happening, any help regarding the same will be much appreciated.