I want to make it so that the text I enter into the JTextField fruit is read on button press, and prints "apple" if the entered text is apple, and "not apple" if the entered text is not.
However, even when I enter "apple" it runs through the else statement and prints "not apple" and I cannot figure out why this is happening. My code is below:
submit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
String enter = fruit.getText();
String fruit2 = enter.toUpperCase();
if (fruit2 == "APPLE") {
System.out.println("apple");
} else {
System.out.println("not apple");
}
}
});