wood burning stoves
The moose likes Beginning Java and the fly likes Comparing two strings?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Comparing two strings??" Watch "Comparing two strings??" New topic

Comparing two strings??

Steve Morrison

Joined: Oct 30, 2003
Posts: 6
I'm trying to get a program to take a string from user input and search an array to try and find a match for it. Now, the data in the string was extracted using StringTokenizer. My problem is...I can't get it to work.
Here's a bit o' code...

O.k...One of the movie titles (it's part of the program, don't ask ) that I'm searching for is Braveheart. I put it in as user input and it's definitely in the array but the program says they don't equal one another. Any ideas as to why? Is it glaring me in the face? Any help would be great! Thanks!
And if there's anything else that I could change about the code to make it better (or more proper for that matter), PLEASE let me know.
Edit: Also, that break that I've got in my loop in the findInStock method kind of bugs me. What's a nice, effective, better way to get rid of that where I can break the loop when a match is found?
[ December 02, 2003: Message edited by: Sam Morrison ]
[ December 02, 2003: Message edited by: Sam Morrison ]
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33130

You should use String equality:
if (searchTitle.equals(dvd[i].getTitle()))
== checks that the strings are the same object while .equals() checks they are the same value.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Steve Morrison

Joined: Oct 30, 2003
Posts: 6
I'm now kicking myself for overlooking the obvious........now I'm done.
That was much appreciated.
I agree. Here's the link: http://aspose.com/file-tools
subject: Comparing two strings??
jQuery in Action, 3rd edition