zoukankan      html  css  js  c++  java
  • Map接口的一些常用方法

    public class NewTestMap {
        public static void main(String[] args) {
            Map<String, String> map = new HashMap<String, String>();
            
            map.put("qqq", "淄博张店");
            map.put("www", "潍坊");
            map.put("eee", "桓台");
            map.put("rrr", "枣庄");
            
            Set<String> keySet = map.keySet();
            for(Object o : keySet) {
                System.out.println(o);
            }
            Collection<String> c = map.values();
            System.out.println(keySet);
            System.out.println(c);
            
            List<String> list = new ArrayList<String>();
            Map<String, Integer> map1 = new HashMap<String, Integer>();
            Set<String> set = new HashSet<String>();
          System.out.println(map.get("rrr"));
            //Object o = map.remove("qqq");
            Object o = map.remove("qqq", new String("淄博张店"));
            System.out.println(o);
            System.out.println(map);
            System.out.println("是否包含某个键: "+map.containsKey("fff"));
            System.out.println("是否包含某个键的值: "+map.containsValue("桓台"));
            System.out.println(map.size());

      例题:用集合(List, Set, Map中任意一种)的知识把星座的题目再写一下

    public class PractiseNew {
        public static void main(String[] args) {
          String _info = "天蝎座,金牛座";    Map
    <String, String> map = new HashMap<String, String>(); String[] xzName = { "白羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座", "天蝎座", "射手座", "摩羯座", "水瓶座", "双鱼座" }; String[] xzDate = { "03月21日─04月20日", "04月21日─05月20日", "05月21日─06月21日", "06月22日─07月22日", "07月23日─08月22日", "08月23日─09月22日", "09月23日─10月22日", "10月23日─11月21日", "11月22日─12月21日", "12月22日─01月19日", "01月20日─02月18日", "02月19日─03月20日" }; for (int i = 0; i < xzName.length; i++) { map.put(xzName[i], xzDate[i]); } String[] infos = _info.split(","); for (String s : infos) { System.out.println(map.get(s) == null ? "没有找到该星座的日期" : s + ":" + map.get(s)); } } }
  • 相关阅读:
    SQL创建的几种存储过程
    关于freemaker的一点使用技巧
    freemaker时间格式转换,精确到毫秒
    递归算法
    网易开发工程师编程题 比较重量 Java
    JavaScript tasks, microtasks, queues and schedules
    1000分以下局目标
    Lua简介
    浅谈Wireshark的基本操作
    adb操作
  • 原文地址:https://www.cnblogs.com/bekeyuan123/p/6905888.html
Copyright © 2011-2022 走看看