TreeMap with Looping
- 7th Oct 2018
- 0
- 8285
- how to iterate treemap elements in java how to loop through treemap elements in java Iterating TreeMap looping treemap elements in java
We can iterate TreeMap using enhanced for loop with keyset() method or by using enhanced for loop with EntrySet method or by using iterator Case 1 Enhanced for loop with keyset() Example import java.util.*; public class TreeMapEnhancedForLoopExample { public static void main(String args[]) { TreeMap<Integer,String> tm = new TreeMap<>(); tm.put(3, “Three”); tm.put(1, “One”); tm.put(2, […]