-
November 21st, 2006, 03:03 AM
#1
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
-
November 21st, 2006, 03:15 AM
#2
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
Byron Tymvios
Please use [ CODE ] and [/ CODE ] tags when posting code! See THIS on how to use code tags.
-
November 21st, 2006, 03:19 AM
#3
Re: string comparison?
thanks a lot, sure you helped
and thanks for the extra infos about the object reference comparison
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|