• Post Reply Bookmark Topic Watch Topic
  • New Topic

Strange goings on with Hashtable

 
Alex Ioannou
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok we all know that Strings are immutable, and that Strings with the same characters share the same characters in memory.
So with hashtables, it's possible to do this :-

so that

all work.
But, I have found a case where this doesn't work, and I can't figure out why. Here is some code:-

So the code selects all weeks in the table, and builds an arraylist of beans for each week.
But if I say that the week is "17-JULY" and try and do a null object is returned. I thought that maybe the value was never stored, so I did an iterator on the keys and the week existed! I also iterated on the values and the object was there also!
I also did :-

The only way I could get the code above to return true was to pass in the original string that was used in the put method.
So what's going on there? Has anyone seen this problem before? I'm using j2sdk1.4.1.
Alex
 
Alex Ioannou
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, to be safe on .equals I did .equalsIgnoreCase() and used .trim() on both strings.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!