This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
internet detective

Joined: May 26, 2003
Posts: 30138

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.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Steve Morrison

Joined: Oct 30, 2003
Posts: 6
I'm now kicking myself for overlooking the I'm done.
That was much appreciated.
Consider Paul's rocket mass heater.
subject: Comparing two strings??
Similar Threads
GC Overhead limit exceeded error when reading a text file
i guess using variables from one class into another class all in the same package?
Test Input Calculator Help
reading from a text file
How to use Collections.binarySearch()