ConcurrentSkipListMap clear() method in Java with Examples
The clear() method of java.util.concurrent.ConcurrentSkipListMap is an in-built function in Java which removes all of the mappings from this map. This means that all the elements from the map are removed and an empty map is returned.
Syntax:
public void clear()
Parameter: The function does not accepts any parameters.
Return Value: The function removes all the mappings from this map.
Below programs illustrate the above method:
Program 1:
// Java Program Demonstrate clear() // method of ConcurrentSkipListMap import java.util.concurrent.*; class GFG { public static void main(String[] args) { // Initializing the map ConcurrentSkipListMap<Integer, Integer> mpp = new ConcurrentSkipListMap<Integer, Integer>(); // adding elements in map for (int i = 1; i <= 5; i++) mpp.put(i, i); // print original map System.out.println("map elements are: " + mpp); mpp.clear(); // after clear() operation System.out.println("after clear the map is: " + mpp); } } |
map elements are: {1=1, 2=2, 3=3, 4=4, 5=5}
after clear the map is: {}
Program 2:
// Java Program Demonstrate clear() // method of ConcurrentSkipListMap import java.util.concurrent.*; class GFG { public static void main(String[] args) { // Initializing the map ConcurrentSkipListMap<Integer, Integer> mpp = new ConcurrentSkipListMap<Integer, Integer>(); // adding elements in map for (int i = 1; i <= 10; i++) mpp.put(i, i); // print original map System.out.println("map elements are: " + mpp); mpp.clear(); // after clear() operation System.out.println("after clear the map is: " + mpp); } } |
map elements are: {1=1, 2=2, 3=3, 4=4, 5=5, 6=6, 7=7, 8=8, 9=9, 10=10}
after clear the map is: {}
Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentSkipListMap.html#clear–
Recommended Posts:
- ConcurrentSkipListMap put() method in Java with Examples
- ConcurrentSkipListMap containsKey() method in Java with Examples
- ConcurrentSkipListMap equals() method in Java with Examples
- ConcurrentSkipListMap isEmpty() method in Java with Examples
- ConcurrentSkipListMap size() method in Java with Examples
- ConcurrentSkipListMap clone() method in Java with Examples
- ConcurrentSkipListMap containsValue() method in Java with Examples
- ConcurrentSkipListMap ceilingKey() method in Java with Examples
- ConcurrentSkipListMap remove() method in Java with Examples
- Set clear() method in Java with Examples
- EnumMap clear() Method in Java with Examples
- AbstractList clear() method in Java with Examples
- Calendar clear() Method in Java with Examples
- AbstractMap clear() Method in Java with Examples
- Properties clear() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



