944,055 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 57501
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
Feb 27th, 2008
0

String.equals()

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
eddy556 is offline Offline
32 posts
since Jan 2008
Feb 27th, 2008
-1

Re: String.equals()

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.
Reputation Points: 9
Solved Threads: 1
Light Poster
Parsu7 is offline Offline
29 posts
since Feb 2008
Feb 27th, 2008
0

Re: String.equals()

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..
Reputation Points: 10
Solved Threads: 2
Newbie Poster
striker3344 is offline Offline
19 posts
since Dec 2007
Feb 27th, 2008
0

Re: String.equals()

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
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Oct 20th, 2009
0
Re: String.equals()
Click to Expand / Collapse  Quote originally posted by Ezzaral ...
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!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Chad W is offline Offline
5 posts
since Oct 2009
Oct 20th, 2009
0
Re: String.equals()
Haha good to see an old post is still helping people
Reputation Points: 10
Solved Threads: 0
Light Poster
eddy556 is offline Offline
32 posts
since Jan 2008
Oct 20th, 2009
0
Re: String.equals()
can i use like these ?
String a = "Hello";
if ( a == "Hello" )

am php programmer .. never try java.

thx .
Reputation Points: 10
Solved Threads: 0
Newbie Poster
truebot is offline Offline
11 posts
since Oct 2007
Oct 20th, 2009
0
Re: String.equals()
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...
Reputation Points: 10
Solved Threads: 0
Light Poster
eddy556 is offline Offline
32 posts
since Jan 2008
Oct 20th, 2009
0
Re: String.equals()
Click to Expand / Collapse  Quote originally posted by eddy556 ...
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
truebot is offline Offline
11 posts
since Oct 2007
Oct 20th, 2009
0
Re: String.equals()
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Chad W is offline Offline
5 posts
since Oct 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Error: <identifier> expected
Next Thread in Java Forum Timeline: check if string contains any capitals





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC