I was wondering how I could make my program exit a loop when the user inputs a specific keyword? I have already figured out how to do this with integers, but I want to know how to incorporate this with Strings.
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while (true) {
System.out.println("type words.");
System.out.println("type stop to exit the program.");
String uInput = input.nextLine();
if (uInput == "STOP") {
System.out.println("exit successful");
break;
}
}
}
}