I am writing a simple program to get to grips with using the Scanner in Java. The program has a stored value for user_1 and asks the user to provide the String variable username which is then checked against user_1 using the == operator, however even when username matches user_1 it still evaluates to false. I'm sure I must be missing something simple, any help would be appreciated. I even added the line printing both variable just to double check they are the same!!
import java.util.Scanner;
public class HelloWorld {
public static void main(String[] args) {
String user_1 = ("lucasRHCP");
Scanner input = new Scanner(System.in);
System.out.println("Enter your username: ");
String username = input.nextLine();
System.out.println(user_1 + " " + username);
if (username == user_1){
System.out.println("True");
}
else {
System.out.println("False");
}
}
}