首页 > 其他 > 详细

Map接口的类实现

时间:2019-03-25 13:16:47      阅读:186      评论:0      收藏:0      [点我收藏+]
public class MapText {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Map<String, String>map = new HashMap<>();
        
        Emp emp = new Emp("351", "张三");
        Emp emp2 = new Emp("512", "李四");
        Emp emp3 = new Emp("853", "王一");
        Emp emp4 = new Emp("125", "赵六");
        Emp emp5 = new Emp("341", "黄七");
        
        map.put(emp.getE_id(), emp.getE_name());
        map.put(emp2.getE_id(), emp2.getE_name());
        map.put(emp3.getE_id(), emp3.getE_name());
        map.put(emp4.getE_id(), emp4.getE_name());
        map.put(emp5.getE_id(), emp5.getE_name());
        
        Set<String>set = map.keySet();
        Iterator<String> it = set.iterator();
        System.out.println("HashMap类实现Map集合,无序:");
        while(it.hasNext()){
            String str = (String)it.next();
            String name = (String)map.get(str);
            System.out.println(str + " " + name);
        }
        TreeMap<String, String> treeMap = new TreeMap<>();
        treeMap.putAll(map);
        Iterator<String> iter = treeMap.keySet().iterator();
        System.out.println("TreeMap类实现的Map集合,键对象升序: ");
        while(iter.hasNext()){
            String str = (String)iter.next();
            String name = (String)treeMap.get(str);
            System.out.println(str + " " + name);
        }
        
        
    }

}

 

Map接口的类实现

原文:https://www.cnblogs.com/dulute/p/10593026.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!