I'm working on creating a symbol table for a parser I am writing and I am using a hashtable to implement my symbol table. I'm running into some trouble when I try to print out the values in my table. Here's what I'm doing:
here is my driver:
Any help would be great.
"If the facts don't fit the theory, get new facts" --Albert Einstein
element = (String)iterator.nextElement(); it gives you a value element of Hashtable which is SymbolTableEntry . SymbolTableEntry is not a String , but you are trying to cast to String, so Obviously you get *ClassCastException*
Note that classes Hashtable and Enumeration are legacy collection classes. They have been (more or less) replaced by the collections framework in Java 1.2 (a long time ago!). See Sun's tutorial about collections for more information.
Use HashMap instead of Hashtable and Iterator instead of Enumeration.