Hash Tables

Posted on 2002-07-08
Last Modified: 2010-03-31
How can I get the key value out of this hashmap along with the values.  Currently I am trying to set the values myself but this is not working very well.

Hashtable h = com.mycompany.catalog.PaymentTypes.getTypeList();

int x=0;
Enumeration e = h.elements();
int paymentValue = 0;
int baseValue = 999;
while (e.hasMoreElements()) {
     x += 1;
     paymentValue = baseValue + x;
     cboPaymentType.insert(e.nextElement().toString (),String.valueOf(paymentValue),x);

//returning object
public static Hashtable getTypeList() {
     Hashtable h = new Hashtable();
     for (int i = 1000; i<1011; i++){
     return h;
Question by:CSharpRules
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 86

Expert Comment

ID: 7137989
Enumeration e = h.keys() will return the keys

Accepted Solution

yongsing earned 30 total points
ID: 7138026
Hashtable h = com.mycompany.catalog.PaymentTypes.getTypeList();

for (Enumeration e = h.keys(); e.hasMoreElements()) {
   Object key = e.nextElement(); // get the key
   Object value = h.get(key); // get the value

Expert Comment

ID: 7138237
h.keys() returns an enumeration of the keys. You can loop over it and read the keys one by one.
h.get(key) returns the value corresponding to the key 'key'.

Author Comment

ID: 7157396
I could not get the loop to work but knowing the syntax of
Object key = e.nextElement();
Object value = h.get(key);


Expert Comment

ID: 7158476
There is a mistake in my for loop. You need to place a semi-colon in it:

Hashtable h = com.mycompany.catalog.PaymentTypes.getTypeList();

for (Enumeration e = h.keys(); e.hasMoreElements();) {
  Object key = e.nextElement(); // get the key
  Object value = h.get(key); // get the value

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
Unhandled exception type Exception 18 52
Need Help! Getting a syntax error and don't understand why 3 39
Setup GlassFish 4 35
program arguments vs VM arguments 4 28
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

749 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