ConcurrentSkipListMap put() method in Java with Examples
The put() method of java.util.concurrent.ConcurrentSkipListMap is an in-built function in Java which associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced.
Syntax:
public V put(K key, V value)
Parameter: The function accepts two mandatory parameters:
- key which specifies the key with which the specified value is to be associated
- value: which specifies the value to be associated with the specified key.
Return Value: The function returns the previous value associated with the specified key. If there was no mapping for the specified key, then this method returns null.
Below programs illustrate the above method:
Program 1:
// Java Program Demonstrate put() // 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 to this map for (int i = 1; i <= 5; i++) mpp.put(i, i); // put() operation on the map System.out.println("After put(): " + mpp); } } |
After put(): {1=1, 2=2, 3=3, 4=4, 5=5}
Program 2:
// Java Program Demonstrate put() // 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 to this map for (int i = 1; i <= 9; i++) mpp.put(i, i); // put() operation on the map System.out.println("After put(): " + mpp); } } |
After put(): {1=1, 2=2, 3=3, 4=4, 5=5, 6=6, 7=7, 8=8, 9=9}
Reference: https://docs.oracle.com/javase/9/docs/api/java/util/concurrent/ConcurrentSkipListMap.html#put-K-V-
Recommended Posts:
- ConcurrentSkipListMap remove() method in Java with Examples
- ConcurrentSkipListMap ceilingKey() method in Java with Examples
- ConcurrentSkipListMap isEmpty() method in Java with Examples
- ConcurrentSkipListMap size() method in Java with Examples
- ConcurrentSkipListMap containsKey() method in Java with Examples
- ConcurrentSkipListMap clone() method in Java with Examples
- ConcurrentSkipListMap clear() method in Java with Examples
- ConcurrentSkipListMap equals() method in Java with Examples
- ConcurrentSkipListMap containsValue() method in Java with Examples
- Java lang.Long.byteValue() method in Java with Examples
- Java lang.Long.highestOneBit() method in Java with Examples
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java lang.Long.lowestOneBit() method in Java with Examples
- Java.util.Collections.disjoint() Method in java with Examples
- Java.util.Collections.rotate() 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.



