1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
/* Remove all values from Java TreeMap example This Java Example shows how to remove all values from TreeMap object or empty TreeMap or clear TreeMap using clear method. */ import java.util.TreeMap; public class EmptyTreeMapExample { public static void main(String[] args) { //create TreeMap object TreeMap treeMap = new TreeMap(); //add key value pairs to TreeMap treeMap.put("1","One"); treeMap.put("2","Two"); treeMap.put("3","Three"); /* To remove all values or clear TreeMap use void clear method() of TreeMap class. Clear method removes all key value pairs contained in TreeMap. */ treeMap.clear(); System.out.println("Total key value pairs in TreeMap are : " + treeMap.size()); } } /* Output would be Total key value pairs in TreeMap are : 0 */ |
Add Comment