This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "hashtable" Watch "hashtable" New topic
Author

hashtable

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
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

Joined: Jan 30, 2000
Posts: 18671


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hashtable
 
Similar Threads
help with testing a hashtable
help with some code.
help with a sql statement
delete values from a hastable
ArrayList