Solved

Hashtable get() method

Posted on 2004-09-01
1
295 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
for i loop in grovy 1 44
Hibernate Not Rolling Back When something fails in a stored procedure 2 51
javap bin 2 27
difference of if loops 23 40
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…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

910 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now