Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
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


Win a copy of The Software Craftsman this week in the Agile forum!
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! :-)
 
Have you tried LearnNowOnline? http://www.learnnowonline.com/
 
subject: "String" = "String" = False...?