Tuesday, April 22, 2014

Compare substring with string?








Why isn't it working?












Java Code:











if ((line.substring(i,i+2)) == "go")
break;









I printed this to check if substring works fine, used this:











Java Code:











System.out.println(line.substring(i,i+2) + " : "+ length);









So, output:







Er : 1







ra : 2







ag : 3







go : 4







on : 5







n' : 6







'> : 7



Line:







String line = "Eragon'>";








Shouldn't it break loop after printing "go : 4"?







line.substring(i,i+2) prints go here. But if doesn't work.







What is wrong?















No comments:

Post a Comment