public static void printMap(Map mp) {
Iterator it = mp.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
System.out.println(pair.getKey() + " = " + pair.getValue());
it.remove(); // avoids a ConcurrentModificationException
}
}
Labels
- Two Pointers (9)
- String/Array (7)
- Design (5)
- Math (5)
- Binary Tree (4)
- DFS (3)
- HashTable (3)
- Subsets (3)
- Traversal (3)
- Bit Manipulate (2)
- DP (2)
- Greedy (2)
- Heap (2)
- Linked List (2)
- BST (1)
- D&C (1)
- Iterator (1)
- Matrix (1)
- Topological Sort (1)
Friday, March 6, 2015
Iterator over HashMap
How to use iterator to go through a HashMap?
Labels:
Iterator
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment