-
string comparison?
i know this a stupid question, but i don't why this code isn't working:
fct = JOptionPane.showInputDialog("enter a string");
JOptionPane.showMessageDialog(null,fct,"info",JOptionPane.INFORMATION_MESSAGE);
if (fct == "abc")
JOptionPane.showMessageDialog(null,"OK","info",JOptionPane.INFORMATION_MESSAGE);
plz help, i'm new in java
-
Re: string comparison?
Hi
For comparing Strings you need to use the equals() method ie:
Code:
String a = "123";
String b = "123";
if(a.equals(b)){
}
This is because == checks if you are working with the same object reference, it doesn't check the values of the Strings themselves.
Hope This Helps
-
Re: string comparison?
thanks a lot, sure you helped
and thanks for the extra infos about the object reference comparison