java skip函数_Java ConcurrentSkipListMap remove()用法及代码示例

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}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值