• java map排序


    public void statisticsA(){
            List<Moves> file = this.file();
            Map<String,Integer> map = new HashMap<>();
            int init=1;
            for (Moves moves1 : file) {
                if("".equals(moves1.getDate())||moves1.getDate()==null){
                    continue;
                }
                if(map.containsKey(moves1.getDate())){
                    Integer count = map.get(moves1.getDate());
                    map.put(moves1.getDate(),++count);
                }else{
                    map.put(moves1.getDate(),init);
                }
            }
            ArrayList<Map.Entry<String, Integer>> entries = new ArrayList<>(map.entrySet());
            Collections.sort(entries,new Comparator<Map.Entry<String, Integer>>(){
                @Override
                public int compare(Map.Entry<String, Integer> v1, Map.Entry<String, Integer> v2) {
                    return Integer.valueOf(v1.getKey()) - Integer.valueOf(v2.getKey());
                }
            });
            Iterator<Map.Entry<String, Integer>> iterator = entries.iterator();
            while(iterator.hasNext()){
                Map.Entry<String, Integer> next = iterator.next();
                String key = next.getKey();
                Integer value = next.getValue();
                System.out.println("[ "+key+" ]年: 发行( "+value+" )部电影");
            }
        }
  • 相关阅读:
    springmvc+mybatis多数据源切换
    Tomcat 8.5 配置自动从http跳转https
    Tomcat 8.5 配置 域名绑定
    本地测试Tomcat配置Https访问
    Spring boot
    解决IDEA16闪退的问题
    cef
    spring-boot学习资料
    oracle 表空间不足解决办法
    oracle导出表的办法
  • 原文地址:https://www.cnblogs.com/Difcipo/p/14044235.html
Copyright © 2020-2023  润新知