Map put和remove的 使用

来源:互联网 发布:手机如何切换软件 编辑:程序博客网 时间:2024/05/20 18:51



import java.util.HashMap;import java.util.Map;public class TestDemo {public static void main(String[] args) {Map map = new HashMap();      Integer it = map.put("id", new Integer(1));      Integer it1 = map.put("id", new Integer(333));     Integer it2 = map.remove("id");     // 在放入第一个 id 元素的时候,因为之前没有 id,所以返回值为 null      // 在第二次放入 id 的时候,因为之前已经有了一个 id 了,所以在放入新元素之前需要将原来的元素给返回给调用者     //map在remove返回值为key对应的value    System.out.println(it);      System.out.println(it1);    System.out.println(it2);}}
原创粉丝点击