Home arrow static arrow Java Programming [Archive] - Help strings not equal to each other
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Help strings not equal to each other
This topic has 7 replies on 1 page.

Posts:32
Registered: 7/26/04
Help strings not equal to each other  
Jul 26, 2004 7:27 AM



 
If string1.equals(string2) is the equivalent of string1==string2
what is the equivalent to string1!=string2

I need to say if ( u.equals(usernam) && p(does not equal)(password) )

I am sure this is really easy, and i am sorry to bother you all

Thanks in advance

Tom
 

Posts:18,384
Registered: 21.03.00
Re: Help strings not equal to each other  
Jul 26, 2004 7:29 AM (reply 1 of 7)



 
Hi,

If (u.equals(username) && (p.equals(password) = false)) {  //}


/Kaj
 

Posts:349
Registered: 1/8/04
Re: Help strings not equal to each other  
Jul 26, 2004 7:29 AM (reply 2 of 7)



 
If string1.equals(string2) is the equivalent of
string1==string2
what is the equivalent to string1!=string2

They ARE NOT equivelent.

I need to say if ( u.equals(usernam) && p(does not
equal)(password) )

if ( ... && ! p.equal(password) ) {}
 

Posts:1,085
Registered: 4/14/03
Re: Help strings not equal to each other  
Jul 26, 2004 7:30 AM (reply 3 of 7)



 
The ! operator will negate a boolean value.

if ( u.equals(usernam) && !p.equals(password) )
 

Posts:18,384
Registered: 21.03.00
Re: Help strings not equal to each other  
Jul 26, 2004 7:30 AM (reply 4 of 7)



 
Sorry for that:

if (u.equals(username) && (p.equals(password) == false)) {  //}


/Kaj
 

Posts:32
Registered: 7/26/04
Re: Help strings not equal to each other  
Jul 26, 2004 7:32 AM (reply 5 of 7)



 
Thanks a lot all
 

Posts:192
Registered: 30/05/01
Re: Help strings not equal to each other  
Jul 26, 2004 7:34 AM (reply 6 of 7)



 
i think you know what you mean....

but i would be careful in saying

If string1.equals(string2) is the equivalent of string1==string2

because it ain't
if ( u.equals(usernam) &&  !p.equals(password) ){}
 

Posts:1
Registered: 7/26/04
Re: Help strings not equal to each other  
Jul 26, 2004 7:42 AM (reply 7 of 7)



 
Try !(p.equals(pass));
That way if it is the correct password the expression will evaluate false.

Rember the String equals method is VERY different than the == operator.
http://java.sun.com/j2se/1.3/docs/api/java/lang/String.html#equals(java.lang.Object)
 
This topic has 7 replies on 1 page.