I can't believe I can't see what I'm doing wrong as this is something a beginner like me should already be used to...
I have the following code:
boolean doWhile = true;
while (doWhile == true){
String s = sc.nextLine();
if (s == "something"){
doWhile = false;
}
//DoStuff
}
Unfortunately, when s == "something", it doesn't break the loop, but instead continues to read the rest of the code.
I've searched around and a lot of people seem to make this mistake, but in their cases they messed up with the = and == things.
I'm pretty sure = is for assigning and == to check equality.
I also tried while(doWhile) and while(!doWhile) with the boolean to false, but nothing seems to work and I can't seem to wrap my head around something so simple.
EDIT: .equals() doesn't work either. Also, I've used == in this way before and it worked without a problem. Not sure why it's making a fuss right now.
EDIT3: No solution here: How do I compare strings in Java?
The solution was provided by harold.