Solved

Hashtable get() method

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
custom annotations 9 42
fibonacci ten numbers 4 45
type mismatch (Object[] to double[] 4 33
printf performancy 11 73
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to implement Singleton Design Pattern in Java.

828 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