Skip to content

Comment on Retiring a Great Interview Problemparent

Comments

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."

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.