I'm trying to create a method which iterates through a hashtable and returns the key as a string, whats the best way to go about this?
EDIT: copied from comment
Sorry if I didn't make it more clear, I'm trying to do this in Java. I've created a test class
public void runprog() {
hashMap.put("Butter", 50);
hashMap.put("Beans", 40);
for (Object o: hashMap.entrySet() ) {
Map.Entry entry = (Map.Entry) o;
System.out.println(entry.getKey() + " " + entry.getValue());
}
}
it outputs
Butter 50 Beans 40
I've created a method which looks for a Key and returns the value
public Object findValue(String Name){
for (Object o: hashMap.entrySet()) {
Map.Entry entry = (Map.Entry) o;
return entry.getValue();
}
return null;
}
when I look for Butter it returns 50 when i look for Beans it returns 50