• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hashtable

 
ben riches
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
thanks
loftty
import java.io.*;
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)){


System.out.println(se);
}
}
}
}
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic