File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes hashtable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "hashtable" Watch "hashtable" New topic


ben riches
Ranch Hand

Joined: Nov 08, 2002
Posts: 126
hello everyone i hope someone can help me
i have the code below which prints out ben twice which is fine. but how would i get the key names of the (st and s ) which should say hello and id.
so i want where the se.equals(st1) part is it gets 2 values but also i want to be able to get the values of there key names aswell
if someone could give me some ideas it would be most grateful
import java.util.*;
import java.lang.*;

public class Has {
public static void main(String[] args) {
ArrayList arr = new ArrayList();
Hashtable hash = new Hashtable();
String st;
String s;
String st1 = new String("ben");
String st2 = new String("alex");
String st3 = new String("ben");
String st4 = new String("cust");
hash.put(st = "hello", st1);
hash.put("b", st2);
hash.put(s = "id", st3);
hash.put("d", st4);

Enumeration e = hash.elements();
while (e.hasMoreElements()) {
String se = (String)e.nextElement();

if (se.equals(st1)){

Jim Yingst

Joined: Jan 30, 2000
Posts: 18671

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: hashtable
jQuery in Action, 3rd edition