Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Questing about String

  Asked By: Trupti    Date: Feb 20    Category: Java    Views: 709
  

I have very quick question. If you have answer please let me know,
i really appriciated your time. I have two string. In order to
check if they equal

String a = "test"
String b = "test1"
String c = "test" // notice string c is same as string a

for compare
if( a.equals(b) )
I got False
if( a.equals(c))
I got True
my question is how do i make second condition to be FAlse. How do i
say NOT equal syntax in java.

I hope you understand what I Am trying to say..

Share: 

 

6 Answers Found

 
Answer #1    Answered By: Mansur Bashara     Answered On: Feb 20

Your sayig you want to check that a does not equal c?
If so then:

if(!a.equals(c))
{
//code This will be executed if a does _not_ equal c
}

Notice the '!', that is the inverse operator, which is will turn true to
false, and false  to true, therefore the above logic would work.
Hope I understood you correctly, and vice versa

 
Answer #2    Answered By: Farah Khan     Answered On: Feb 20

should be if(a!=c)..........................

 
Answer #3    Answered By: Eline Bakker     Answered On: Feb 20

Remember that will only work if the Strings are created literally, and not
with new String(..);

 
Answer #4    Answered By: Harriet Hughes     Answered On: Feb 20

i think this should be work
if( !(a.equals(c))

 
Answer #5    Answered By: Blandina Garcia     Answered On: Feb 20

The equals method will check with the contents of the
String are the same while the == will check if the
references are to the same object

so if(a == c) will equate to false.

 
Answer #6    Answered By: Addison Campbell     Answered On: Feb 20

Use the unary ! operator.
if( !a.equals(c))

 
Didn't find what you were looking for? Find more on Questing about String Or get search suggestion and latest updates.




Tagged: