import java.util.*; public class SortedMapExample { public static void main(String[] args) { SortedMapsm = new TreeMap<>(); sm.put(1, "one"); sm.put(5, "five"); sm.put(3, "three"); System.out.println(sm.size()); // Output: 3 } }
import java.util.*; public class SortedMapExample { public static void main(String[] args) { SortedMapIn this example, we create a ConcurrentSkipListMap object that also implements the SortedMap interface. We add three entries to the map, and then print its size, which is again 3. The SortedMap interface is part of the java.util package library.sm = new ConcurrentSkipListMap<>(); sm.put("one", 1); sm.put("five", 5); sm.put("three", 3); System.out.println(sm.size()); // Output: 3 } }