It's not a secret anymore!*
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
Author

"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="http://www.geocities.com/pricklymustard/freestuff.html" target="_blank" rel="nofollow">http://www.geocities.com/pricklymustard/freestuff.html</a> . I am looking for referrals which is why I need YOU!
Hung Yee
Greenhorn

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:
http://java.sun.com/developer/JDCTechTips/2004/tt0504.html#2
Justin Porter
Ranch Hand

Joined: Nov 20, 2004
Posts: 34
Thanks bunches, definitely helped! :-)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: "String" = "String" = False...?
 
Similar Threads
recursion problem
Trying to create an arraylist of objects based on information from a text file
Code explaination
Need Help with Sorting a split string
String Functions