java.util.concurrent.ConcurrentSkipListMap的remove()方法是Java中的内置函数,该函数从此映射中删除指定键的映射。如果该特定键没有映射,则该方法返回null。执行此方法后,将减小Map的大小。
用法:
ConcurrentSkipListMap.remove(Object ob)
参数:该函数接受单个强制性参数ob,它指定要删除其映射的键。
返回值:该函数返回与指定键关联的先前值;如果键没有映射,则返回null。
以下示例程序旨在说明上述方法:
// Java Program Demonstrate remove()
// method of ConcurrentSkipListMap
import java.util.concurrent.*;
class GFG {
public static void main(String[] args)
{
// Initializing the map
ConcurrentSkipListMap
mpp = new ConcurrentSkipListMap
Integer>();
// Adding elements to this map
for (int i = 1; i <= 5; i++)
mpp.put(i, i);
// remove() operation on the map
mpp.remove(1);
System.out.println("After remove(): " + mpp);
}
}
输出:
After remove(): {2=2, 3=3, 4=4, 5=5}
示例2:
// Java Program Demonstrate remove()
// method of ConcurrentSkipListMap
import java.util.concurrent.*;
class GFG {
public static void main(String[] args)
{
// Initializing the map
ConcurrentSkipListMap
mpp = new ConcurrentSkipListMap
Integer>();
// Adding elements to this map
for (int i = 1; i <= 5; i++)
mpp.put(i, i);
// remove() operation on the map
mpp.remove(5);
System.out.println("After remove(): " + mpp);
}
}
输出:
After remove(): {1=1, 2=2, 3=3, 4=4}