Java中的ConcurrentSkipListMap remove()方法(附例)

Java中的ConcurrentSkipListMap remove()方法(附例)

java.util.concurrent.ConcurrentSkipListMapremove() 方法是Java内置函数,用于从该映射中删除特定键的映射。如果没有特定键的映射,则该方法返回null。执行此方法后,地图的大小会减小。

语法:

ConcurrentSkipListMap.remove(Object ob)

参数:

该函数接受单个强制参数 ob ,指定要删除其映射的键。

返回值:

该函数返回与指定键关联的先前值,如果键没有映射,则返回null。

以下程序说明了上述方法:

//Java程序演示ConcurrentSkipListMap的remove()方法

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);
        // 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程序演示ConcurrentSkipListMap的remove()方法

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);
        // remove() operation on the map
        mpp.remove(5);

        System.out.println("After remove(): " + mpp);
    }
}
输出:After remove(): {1=1, 2=2, 3=3, 4=4}

参考:

https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentSkipListMap.html#remove-java.lang.Object-

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程