File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark ""String" = "String" = False...?" Watch ""String" = "String" = False...?" New topic

"String" = "String" = False...?

Justin Porter
Ranch Hand

Joined: Nov 20, 2004
Posts: 34
Hey, I'm trying to check and see if two strings are equal or not in a particular function. Here is my code:

It always returns -1, even if the substring is exactly the same as 'name'. I proved this with a S.O.PL statement... so what am I doing wrong here? Any help wouldl be appreciated! Thanks!

Want a free iPod, digital camera, or $300 cash? Completely legit offer at <a href="" target="_blank" rel="nofollow"></a> . I am looking for referrals which is why I need YOU!
Hung Yee

Joined: Dec 22, 2004
Posts: 18
You need to use the 'equals()' method in the String class to test for string equality. See this tech tip article from Sun for more details about string equality:
Justin Porter
Ranch Hand

Joined: Nov 20, 2004
Posts: 34
Thanks bunches, definitely helped! :-)
I agree. Here's the link:
subject: "String" = "String" = False...?
It's not a secret anymore!