zoukankan      html  css  js  c++  java
  • 排序

    1、collection          ---[1]

    public static void main(String[] args) {
    		Map<String, Info> map = new HashMap<>();
    		
    		Info info1 = new Info("xxxx", "hhhh", "1980-11-01");
    		Info info2 = new Info("xxxx", "hhhh", "1983-11-22");
    		Info info3 = new Info("xxxx", "hhhh", "1925-11-01");
    		
    		map.put("小杰杰", info1);
    		map.put("你好", info2);
    		map.put("你好1", info3);
    		
    		List<Map.Entry<String,Info>> list = new ArrayList<Map.Entry<String,Info>>(map.entrySet());
    		
    		Collections.sort(list, new Comparator<Map.Entry<String, Info>>() {
    			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    			public int compare(Entry<String, Info> o1, Entry<String, Info> o2) {
    				try {
                        Date dt1 = format.parse(o1.getValue().getTime());
                        Date dt2 = format.parse(o2.getValue().getTime());
                        if (dt1.getTime() > dt2.getTime()) {
                            return 1;
                        } else if (dt1.getTime() < dt2.getTime()) {
                            return -1;
                        } else {
                            return 0;
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
    				return 0;
    			};
    		});
    		
    		for(Map.Entry<String,Info> mapping : list){ 
                System.out.println(mapping.getKey()+" : "+mapping.getValue()); 
    		} 
    	}
    

    2、comparator

    public Person{
    
      String id;
     
      String name;
    
      Company company
    
      private Set<Company> companies = new TreeSet<>(new Comparator<Company>
      {
            @Overrider
            public int compare(Company c1. Company c2){
           
                  return Collator.getInstance(Locale.CHINESES).
              compare(c1.getCompanyName(),c2.getCompanyName())
    
    
            }
    
       }) ;
    
    } 
    

    ========================================================================

    [1] : https://blog.csdn.net/jiejiexiao/article/details/86164315

  • 相关阅读:
    动态表单功能
    IDEA2019版Run Dashboard调出方案
    js页面传递参数为中文乱码问题解决方法
    layui 一行多列控件时使用table布局
    npm 安装包失败 --- 清除npm缓存
    解析数据库连接字符串 (将Data Source、Initial Catalog、User ID、Password取出)
    SQL SERVER 存储过程语法
    mvc5 跨域访问
    钟表
    MVC session过期如何处理跳转(转)
  • 原文地址:https://www.cnblogs.com/Jomini/p/12563953.html
Copyright © 2011-2022 走看看