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 Hashtables and Maps 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 "Hashtables and Maps" Watch "Hashtables and Maps" New topic

Hashtables and Maps

David Dickinson
Ranch Hand

Joined: Nov 11, 2004
Posts: 66
Hi All,

I'm confused by how a hashtable works? Is it a spreadsheet style collection where you can store multiple columns of information under a key? Or is it limited to just one column per key?


Key, data1, data2, data3

I need a collection which can store a series of data which is related

juliane gross
Ranch Hand

Joined: May 30, 2002
Posts: 161
Hi David,

the bad news is,that in a Hashtable you can store one value per one key only.
If you for example put in a value under a same key which was already used, that former key-value-pair will be overwritten by the newly made input.

The good news is, that you do store Objects in Hashtables.
So for example, you coud put in this:

If you need to get back your many things, you just call:

(Don't forget, you always have to cast back your objects to their previous shape.)

An other very cool thing with Hashtables (and their related collection classes) is that you can store in them even whole other classes, interfaces etc. This can be very powerful.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Hashtables and Maps
Similar Threads
Need collection
urgent questions about collection
Creating an object using a variable name?
lock/unlock review
Help regarding Key value pairs