![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
#1 |
Symbol of Cyric
![]() Join Date: October 21, 2004
Location: Vancouver, BC
Age: 36
Posts: 1,143
|
I'm having a little problem with a piece of homework I have to do... Its unlikely that I will get any help by tomorrow, but I'm posting this just on the offchance.
code:public void findIt(String searchValue)[/QUOTE]Its part of a program to hash an array, and this is part of the method to search for a value entered in another class. (A three letter string). I have established that the program is working out the correct hash codes for the searched for variable. The problem seems to lie in the part between the asterisks. Everything else works fine. It just doesn't seem to realise that the string in hash[hashCode] is the same as searchedFor, but they are... without a shadow of doubt as far as I can see...
__________________
[img]\"http://img11.imageshack.us/img11/4763/callumavataranimated4ff.gif\" alt=\" - \" /> |
![]() |
![]() |
![]() |
#2 |
Takhisis Follower
![]() Join Date: April 30, 2001
Location: szép Magyarország (well not right now)
Posts: 5,089
|
Try something like this, I haven't done Java in a long time, so the syntax might not be 100% correct:
if(new String(hash[hashCode]).equals(searchValue)) {...} the point is IIRC you can't compare Strings with the == operator, you need to use the .equals method. And just in case the returned value from has is not in the right format, I'm constructing a new String with it. You can do it in 2 steps as well, to make sure, i.e. String s = new String(hash...) then if s.equals(searchvalue) etc. Let me know if that helps... [ 02-17-2005, 08:17 AM: Message edited by: Vaskez ]
__________________
Too set in his ways to ever relate If he could set that aside, there'd be heaven to pay But weathered and aged, time swept him to grave Love conquers all? Damn, I'd say that area's gray |
![]() |
![]() |
![]() |
#3 |
Symbol of Cyric
![]() Join Date: October 21, 2004
Location: Vancouver, BC
Age: 36
Posts: 1,143
|
dammit!
Thanks... only a few months into the course and forgetting all I've learned [img]tongue.gif[/img]
__________________
[img]\"http://img11.imageshack.us/img11/4763/callumavataranimated4ff.gif\" alt=\" - \" /> |
![]() |
![]() |
![]() |
#4 |
Takhisis Follower
![]() Join Date: April 30, 2001
Location: szép Magyarország (well not right now)
Posts: 5,089
|
so did it work? I wanna know if I remembered correctly!
![]()
__________________
Too set in his ways to ever relate If he could set that aside, there'd be heaven to pay But weathered and aged, time swept him to grave Love conquers all? Damn, I'd say that area's gray |
![]() |
![]() |
![]() |
#5 |
Symbol of Cyric
![]() Join Date: October 21, 2004
Location: Vancouver, BC
Age: 36
Posts: 1,143
|
Yes... Except I used equalsIgnoreCase to be clever
![]()
__________________
[img]\"http://img11.imageshack.us/img11/4763/callumavataranimated4ff.gif\" alt=\" - \" /> |
![]() |
![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
JAVA Help Needed | Timber Loftis | General Discussion | 4 | 04-29-2005 04:02 PM |
More Java Help | Callum | General Discussion | 4 | 03-14-2005 08:19 PM |
Window XP and JAVA help!! | AngelofDeath | General Conversation Archives (11/2000 - 01/2005) | 2 | 10-31-2003 11:50 AM |
Could someone help me with a Java/IE prob? | Melusine | General Conversation Archives (11/2000 - 01/2005) | 8 | 04-13-2003 03:24 AM |
Java help needed | Memnoch | General Conversation Archives (11/2000 - 01/2005) | 5 | 05-27-2002 06:16 AM |