zoukankan      html  css  js  c++  java
  • hashmap可以用null为键值

    import java.util.HashMap;

    import java.util.Map;
    import java.util.TreeMap;
     
    public class TestMain {
        public static void main(String[] args) {
     
            // HashMap可以的键值可以是null, "".
            Map<String, String> strMap1 = new HashMap<String, String>();
            strMap1.put(null, "1");
            strMap1.put("", "2");
            strMap1.put(" ", "3");
            strMap1.put(null, "4");
            System.out.println(strMap1.get(null));
            for (String s : strMap1.keySet()) {
                System.out.println(s);
            }
            for (String s : strMap1.values()) {
                System.out.println(s);
            }
             
            // TreeMap的键值不能是null
            Map<String, String> strMap2 = new TreeMap<String, String>();
            strMap2.put(null, "1");
            //strMap2.put("", "2");
            //strMap2.put(" ", "3");
            //strMap2.put(null, "4");
            //System.out.println(strMap2.get(null));
            for (String s : strMap2.keySet()) {
                System.out.println(s);
            }
            for (String s : strMap2.values()) {
                System.out.println(s);
            }
        }
    }
  • 相关阅读:
    67. Add Binary
    66. Plus One
    64. Minimum Path Sum
    63. Unique Paths II
    How to skip all the wizard pages and go directly to the installation process?
    Inno Setup打包之先卸载再安装
    How to change the header background color of a QTableView
    Openstack object list 一次最多有一万个 object
    Openstack 的 Log 在 /var/log/syslog 里 【Ubuntu】
    Git 分支
  • 原文地址:https://www.cnblogs.com/Seachal/p/7111843.html
Copyright © 2011-2022 走看看