zoukankan      html  css  js  c++  java
  • 黑马程序员JavaAPI16天9(Map扩展)

    package string.test;
    
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Map;
    import java.util.Set;
    
    /*
     * (Map扩展)方式1
     */
    public class MapDemo7 {
        public static void main(String[] args) {
            Map<String, Map<String, String>> map = new HashMap<String, Map<String, String>>();
            Map<String, String> banjia = new HashMap<String, String>();
            banjia.put("a01", "zhangsan");
            banjia.put("a02", "lisi");
            Map<String, String> banjib = new HashMap<String, String>();
            banjib.put("b01", "wangwu");
            banjib.put("b02", "zhaoliu");
            map.put("banjia", banjia);
            map.put("banjib", banjib);
            Set<Map.Entry<String, Map<String, String>>> entrySet = map.entrySet();
            Iterator<Map.Entry<String, Map<String, String>>> iterator = entrySet.iterator();
            while (iterator.hasNext()) {
                Map.Entry<String, Map<String, String>> me = iterator.next();
                String key = me.getKey();
                Map<String, String> value = me.getValue();
                System.out.println(key);
                writeMap(value);
            }
        }
    
        public static void writeMap(Map<String, String> map) {
            Set<Map.Entry<String, String>> entrySet = map.entrySet();
            Iterator<Map.Entry<String, String>> it = entrySet.iterator();
            while (it.hasNext()) {
                Map.Entry<String, String> me = it.next();
                System.out.println("key:" + me.getKey() + ",value:" + me.getValue());
            }
        }
    }
    package string.test;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;
    import java.util.Set;
    
    /*
     * (Map扩展)方式2
     */
    public class MapDemo8 {
    
        public static void main(String[] args) {
            Map<String, List<StudentDemo>> map = new HashMap<String, List<StudentDemo>>();
            List<StudentDemo> banjia = new ArrayList<StudentDemo>();
            banjia.add(new StudentDemo("a01", "zhangsan"));
            banjia.add(new StudentDemo("a02", "lisi"));
            List<StudentDemo> banjib = new ArrayList<StudentDemo>();
            banjib.add(new StudentDemo("b01", "wangwu"));
            banjib.add(new StudentDemo("b02", "zhaoliu"));
            map.put("banjia", banjia);
            map.put("banjib", banjib);
            Set<Map.Entry<String, List<StudentDemo>>> entrySet = map.entrySet();
            Iterator<Map.Entry<String, List<StudentDemo>>> iterator = entrySet.iterator();
            while (iterator.hasNext()) {
                Map.Entry<String, List<StudentDemo>> me = iterator.next();
                String key = me.getKey();
                List<StudentDemo> value = me.getValue();
                System.out.println(key);
                writeMap(value);
            }
        }
    
        public static void writeMap(List<StudentDemo> stus) {
    
            Iterator<StudentDemo> it = stus.iterator();
            while (it.hasNext()) {
                StudentDemo me = it.next();
                System.out.println("key:" + me.getId() + ",value:" + me.getName());
            }
        }
    
    }
    
    class StudentDemo {
        private String id;
        private String name;
    
        public String getId() {
            return id;
        }
    
        public void setId(String id) {
            this.id = id;
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public StudentDemo(String id, String name) {
            this.id = id;
            this.name = name;
        }
    
    }
  • 相关阅读:
    导入贴图操作:处理贴图MaxSize和Format
    修改贴图工具
    CharacterMotor_刚体角色驱动
    sine曲线向前运动
    Shader基础(固定管线着色器)
    Shader基础(渲染管线)
    Unity3D中的高级摄像机跟随
    蛋疼的 qii 神马警告才是需要注意的警告?(由于警告引起的截然不同的运行结果)
    模拟摄像头,AV视频信号线解码,PAL制 NTSC,输入解码显示,终于搞定,记录下!
    VIP 视频开发板 上位机 测试软件 下载地址,玩转各自分辨率(V201抢先版)
  • 原文地址:https://www.cnblogs.com/guwenren/p/2971056.html
Copyright © 2011-2022 走看看