4 ms·
FYI - there's a potential defect there - keys are not required to be strings so you should lookup the value before you cast.
by phillytom 15y ago
FYI - there's a potential defect there - keys are not required to be strings so you should lookup the value before you cast.
- free 15y agoIdeally, 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()); }
- nitrogen 15y agoI 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."