This question already has an answer here:
- How do I compare strings in Java? 23 answers
Why does this output False?
import javax.swing.JLabel;
public class gettext {
public static void main(String[] args) {
JLabel User = new JLabel("User");
String GetTxt = new String(User.getText());
if (GetTxt == ("User"))
{
System.out.println(GetTxt);
}
else
{
System.out.println("False");
}
}
}
Aucun commentaire:
Enregistrer un commentaire