The code below is mostly self explanatory. However, I am having trouble in two cases:
The
while
loop does not exit even with the command line is left blank.If the input is
test t1
thekey
variable is supposed to be "test" (usingSystem.out.println(key)
) does that, but, it still doesn't enter theif
condition 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.