有关HashMap的一个method:entrySet()
写一个小程序,用到HashMap,最后想把HashMap中的key-value对显示出来,不想用HashMap的toString,查到HashMap有个
public Set entrySet() 方法
于是拭写了以下代码:
public void printMap()
{
HashSet entries;
entries=new HashSet((HashSet)map.entrySet()); //*******
Iterator iter=entries.iterator();
while(iter.hasNext())
{
System.out.println(iter.next()+" ");
}
}
在eclipse下不能通过编译,是//******行的问题
错误信息:
java.lang.ClassCastException
at wordsCount.printMap(wordsCount.java:50)
at wordsCount.Count(wordsCount.java:46)
at wordsCount.main(wordsCount.java:62)
Exception in thread "main"
????????????????????望指教,谢谢