Comment on Retiring a Great Interview ProblemparentComments−phillytom15yFYI - there's a potential defect there - keys are not required to be strings so you should lookup the value before you cast.−free15yIdeally, whatever your key/value is would have the toString method over ridden to meaningfully represent it. Alternatively, I could write it asfor(Map.Entry<K, V> entry : map.entrySet()){ System.out.println(entry.getKey()); System.out.println(entry.getValue()); }−nitrogen15yI 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."
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()){
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."