Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

FYI - there's a potential defect there - keys are not required to be strings so you should lookup the value before you cast.


Ideally, whatever your key/value is would have the toString method over ridden to meaningfully represent it. Alternatively, I could write it as

for(Map.Entry<K, V> entry : map.entrySet()){

     System.out.println(entry.getKey());

     System.out.println(entry.getValue());

}


I was relying on the assumption from the original question that the keys and values were all Strings: "...a Hashtable containing String keys and values and printing them all out."




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: