String.equals()

Reply

Join Date: Jan 2008
Posts: 32
Reputation: eddy556 is an unknown quantity at this point 
Solved Threads: 0
eddy556 eddy556 is offline Offline
Light Poster

String.equals()

 
0
  #1
Feb 27th, 2008
No I know that in order to compare a String you have to call its method .equals but how I check if a String is NOT equal to something? Will it be something like if ("hello" != String.equal())?? or is there a special method?

I know I'm being dumb here lol but after some researching I can't find the answer.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 28
Reputation: Parsu7 is an unknown quantity at this point 
Solved Threads: 1
Parsu7 Parsu7 is offline Offline
Light Poster

Re: String.equals()

 
-1
  #2
Feb 27th, 2008
two strings are equal in case of equals method if both strings that you are comparing have the same characters and have the same case such as "hello".equals("hello") will return true as both the strings have the same characters h,e,l,l,o and they do have the same length and also have the same case.
Now change the case of h to H i.e write "Hello".equals("hello") this will return false which shows that the strings are not equal.
understood.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 15
Reputation: striker3344 is an unknown quantity at this point 
Solved Threads: 2
striker3344 striker3344 is offline Offline
Newbie Poster

Re: String.equals()

 
0
  #3
Feb 27th, 2008
String.equal() return type is boolean
example:

String a = "not Hello"
if(a.equal("Hello")){
will do whatever here if result is true}

or

if(!a.equal("Hello")){
will do whatever here if result is true}

and so on..
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,438
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 510
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: String.equals()

 
0
  #4
Feb 27th, 2008
Use ( ! "hello".equals(someString) ) edit: Yes, same thing striker just posted
Last edited by Ezzaral; Feb 27th, 2008 at 2:07 pm. Reason: post collision
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 5
Reputation: Chad W is an unknown quantity at this point 
Solved Threads: 0
Chad W's Avatar
Chad W Chad W is offline Offline
Newbie Poster
 
0
  #5
Oct 20th, 2009
Originally Posted by Ezzaral View Post
Use ( ! "hello".equals(someString) ) edit: Yes, same thing striker just posted
Thank you VERY MUCH. I didn't find anything on a not equals method for comparing strings. Placing the not operator before the equals test never occured to me. Oh well, such are the pains of beginning programing classes. Thanks again!
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 32
Reputation: eddy556 is an unknown quantity at this point 
Solved Threads: 0
eddy556 eddy556 is offline Offline
Light Poster
 
0
  #6
Oct 20th, 2009
Haha good to see an old post is still helping people
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 11
Reputation: truebot is an unknown quantity at this point 
Solved Threads: 0
truebot truebot is offline Offline
Newbie Poster
 
0
  #7
Oct 20th, 2009
can i use like these ?
String a = "Hello";
if ( a == "Hello" )

am php programmer .. never try java.

thx .
http://www.jobyess.com - My test web for SEO
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 32
Reputation: eddy556 is an unknown quantity at this point 
Solved Threads: 0
eddy556 eddy556 is offline Offline
Light Poster
 
0
  #8
Oct 20th, 2009
Why don't you just try it? Just by reading the thread (I started it a while back now so can't remember) I would say you need the .equals() method to return for you...
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 11
Reputation: truebot is an unknown quantity at this point 
Solved Threads: 0
truebot truebot is offline Offline
Newbie Poster
 
0
  #9
Oct 20th, 2009
Originally Posted by eddy556 View Post
Why don't you just try it? Just by reading the thread (I started it a while back now so can't remember) I would say you need the .equals() method to return for you...
thank you for reply
i don't have java install ^^" today i learning java and downloading jdk
http://www.jobyess.com - My test web for SEO
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 5
Reputation: Chad W is an unknown quantity at this point 
Solved Threads: 0
Chad W's Avatar
Chad W Chad W is offline Offline
Newbie Poster
 
0
  #10
Oct 20th, 2009
Yes, I bet the frendly people who help here would wish more people would search for answers before posting duplicate questions.

On a side note, I'm going to have to ask for help in a second, since I have a switch statement that just isn't working correctly.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC