java.util.HashMap.remove()方法实例

来源:互联网 发布:听歌不要钱的软件 编辑:程序博客网 时间:2024/05/18 22:40

java.util.HashMap.remove()方法实例

评论  编辑
<iframe id="iframeu1064372_0" src="http://pos.baidu.com/ncpm?rdid=1064372&amp;dc=2&amp;di=u1064372&amp;dri=0&amp;dis=0&amp;dai=1&amp;ps=323x335&amp;dcb=BAIDU_SSP_define&amp;dtm=BAIDU_DUP_SETJSONADSLOT&amp;dvi=0.0&amp;dci=-1&amp;dpt=none&amp;tsr=0&amp;tpr=1459144932123&amp;ti=java.util.HashMap.remove()%E6%96%B9%E6%B3%95%E5%AE%9E%E4%BE%8B&amp;ari=1&amp;dbv=2&amp;drs=1&amp;pcs=1156x572&amp;pss=1156x1476&amp;cfv=0&amp;cpl=4&amp;chi=1&amp;cce=true&amp;cec=UTF-8&amp;tlm=1459144932&amp;ltu=http%3A%2F%2Fwww.yiibai.com%2Fjava%2Futil%2Fashmap_remove.html&amp;ltr=https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DVkT4Wu3jerwwEb_aVTyNxDl-nqpX4imXbibIKyRBSVo1lVaC4ooKlwSDMtzqaESxMxKRWWdZ-TDR7Tva4Eb2B_%26wd%3D%26eqid%3Df3f6d89b0001bfd40000000556f8c8a5&amp;ecd=1&amp;psr=1366x768&amp;par=1366x728&amp;pis=-1x-1&amp;ccd=24&amp;cja=false&amp;cmi=6&amp;col=zh-CN&amp;cdo=-1&amp;tcn=1459144932&amp;qn=9a4841f476805c55&amp;tt=1459144932000.126.312.314" width="728" height="90" align="center,center" vspace="0" hspace="0" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" allowtransparency="true" style="border-width: 0px; border-style: initial; vertical-align: bottom; margin: 0px;"></iframe>

描述

The remove() method is used to remove the mapping for the specified key from this map if present.

声明

Following is the declaration for java.util.HashMap.remove() method.

public V remove(Object key)

参数

  • key--This is the key whose mapping is to be removed from the map.

返回值

The method call returns the previous value associated with key, or null if there was no mapping for key.

异常

  • NA

实例一

编辑+分享实例

以下例子将告诉你如何使用 java.util.HashMap.remove()

package yiibai.com;import java.util.*;public class HashMapDemo {   public static void main(String args[]) {      // create hash map      HashMap newmap = new HashMap();                  // populate hash map      newmap.put(1, "tutorials");      newmap.put(2, "point");      newmap.put(3, "is best");            System.out.println("Values before remove: "+ newmap);            // remove value for key 2      newmap.remove(2);      System.out.println("Values after remove: "+ newmap);   }    }

Let us compile and run the above program, this will produce the following result.

Values before remove: {1=tutorials, 2=point, 3=is best}Values after remove: {1=tutorials, 3=is best}
0 0
原创粉丝点击