This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Hash Tables, Hash Sets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Hash Tables, Hash Sets" Watch "Hash Tables, Hash Sets" New topic
Author

Hash Tables, Hash Sets

Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

Hey everyone,

I've coded in Java for a few semesters now, but not in any of my classes has a hash table or hash set/maps come up. I see people using them in their source code they post on this forum, but i'm not really sure what they do that's better than ways i code. So i was wondering if someone could fill me in on their uses and functionality.


Thanks.
Hunter.


"If the facts don't fit the theory, get new facts" --Albert Einstein
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60041
    
  65

You want to make an association between a key and a value? Map Man to the rescue!


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

a key to encrypt information?? I'm not really sure what you mean.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60041
    
  65

Let's say you want to convert state codes to their names.

What's better:
48 more times

or


?

Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

so for something like what you just described would you need two maps?? one for the stateName and one for the keys? or does one map hold the name and the key ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60041
    
  65

Look up java.util.Map. A single map equates the keys with their values. Some languages refer to these as Dictionaries I believe.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hash Tables, Hash Sets
 
Similar Threads
hashcode
doubt regarding hashcode
hashtable sort
equal() method of class Object
Doubt About Hash Code