• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Comparing two strings??

 
Steve Morrison
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 34656
365
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Steve Morrison
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THANK YOU!
I'm now kicking myself for overlooking the obvious........now I'm done.
That was much appreciated.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic