Hi everybody, i need help with this code:
import java.util.*;
public class HashTable {
public static void main(String...args) {
TreeMap<String, String> tm = new TreeMap<String, String>();
Hashtable<String, String> ht = new Hashtable<String, String>();
tm.put("1", "George");
tm.put("2", "Jim");
tm.put("3", "John");
tm.put("4", "Blake");
tm.put("5", "Kevin");
tm.put("6", "Michael");
tm.put("7", "George");
tm.put("8", "Katie");
tm.put("9", "Kevin");
tm.put("10", "Michelle");
tm.put("11", "Ryan");
tm.put("12", "Michelle");
tm.put("13", "George");
ht.putAll(tm);
Enumeration<String> keys = ht.keys();
while( keys.hasMoreElements() )
{
String name = keys.nextElement();
int count = 0;
for (int j = 0; j<tm.size(); j++)
if(name == tm.get(j))
count++;
System.out.println(name + " " + count);
}
}
}
it is supposed to print out the list of names and how many times each entry occurs in the list, for example
George 3
Ryan 1
and so one. The problem is it lists the names but the occurrence count stays zero, it throws a cast error but i don't know where.
i don't understand why.
Please help.
Thank you