Solved

Hashtable get() method

Posted on 2004-09-01
1
297 Views
Last Modified: 2010-03-31
Ok so this is a really easy question but I just havent used hashtables before.  I have been looking at documentation and I am alittle confused.  I have a bunch of data stored in a hashtable.  Now I want to go through that data element by element and get it out of the hashtable.  I know that I have to use the hashtable get() method however I am not really sure how to do this because the part with the keys kind of confuses me.  I was trying to go through it simply like an array but it did not work.  Can someone kind of give me a hand on how to go through the hashtable with keys?  


Thanks!
0
Comment
Question by:kassidy2010
1 Comment
 
LVL 19

Accepted Solution

by:
ramazanyich earned 125 total points
ID: 11957606
Hashtable h = new Hashtable();
h.put("key","value");
// other h.put() calls;
Enumeration enum = h.keys();
while(enum.hasMoreElements()){
 Object key = enum.nextElement();
 Object value = h.get(key);
 System.out.println(key+":"+value);
}
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
numbers ascending pyramid 101 193
github account with ecipse 1 47
Java JRE greater than 1.6 5 62
How do I remove an object from a 3 23
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question