I want to iterate over a TreeMap
, and for all keys which have a particular value, I want them to be added to a new TreeMap
. How can I do this?
Answer
Assuming type TreeMap
for(Map.Entry entry : treeMap.entrySet()) {
String key = entry.getKey();
Integer value = entry.getValue();
System.out.println(key + " => " + value);
}
(key and Value types can be any class of course)
No comments:
Post a Comment