I have some relatively simple code that I did that was supposed to get an iterator for a HashMap and print out the values โโof a key pair .
My problem is that when I go to get an iterator, I get this exception.
Exception in thread "main" java.lang.ClassCastException: java.util.HashMap $ Record cannot be passed to java.lang.String
in Delete.main (Delete.java:25)
Here is my code, and I indicate where line 25 is:
Map <String, UpdatablePage> contentMap = new HashMap <String, UpdatablePage>(); contentMap.put( "test", new UpdatablePage() ); for ( Iterator it = (Iterator) contentMap.entrySet().iterator(); it.hasNext(); ) { String key = (String) it.next();
PS, I tried iterating over the map using Map.Entry, but when I go to return the value returned by the iterator to Map.Entry, I get another casting exception, why?
// Error occurs when I do the following Map.Entry pair = (Map.Entry) it.next();
source share