Java Check If Two JTextField Has The Same Content [duplicate]
问题 This question already has answers here : How do I compare strings in Java? (23 answers) Closed 6 years ago . I have two JTextFields txf1 and txf2. In both of them I input the same content (for example: "test"). I made and If statement: if (txf1.getText() == txf2.getText()) { System.out.println("Equal"); } else { System.out.println("Error"); } Why it prints out the error message? I even made a System.out.println(txf1.getText()) and System.out.println(txf2.getText()) and the same looks equal,