Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String comparison not working 1

Status
Not open for further replies.

EwS

Programmer
Dec 30, 2002
398
US
I'm trying to compare two strings a and b. When I inspect the variables in Eclipse I see the following:
Code:
a 
value=char[6]
[0]=t
[1]=e
[2]=s
[3]=t
[4]= 
[5]= 

b
value=char[4]
[0]=t
[1]=e
[2]=s
[3]=t
When I do a comparison if (a == b), the if condition is never met. If I hard-code a="test", then the condition is met. What do I have to do so that the condition is met without hard-coding anything?
Thank you.
 
the == compares pointers to each other, not the strings, use value.compareTo() or value.compareToIgnoreCase methods for comparing the contents of strings

HTH
TonHu
 
Thanks, I totally forgot about this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top