Thread: == vs .equals()
View Single Post
Old 05-03-2004, 01:37 PM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,541
sde is on a distinguished road
== vs .equals()

what the heck?

why can't i use == to test for equality between strings with java?

example:
Code:
String myState="CA";
String states = new String[] { "CA","AZ" };

if( states[0]==myState )
{
  // this will always fail
}

if( states[0].equals(myState) )
{
  // this is true
}

i this was mentioned before, but i want to now precisely why.. or is there no good answer?
__________________
Mike
sde is offline   Reply With Quote