zoukankan      html  css  js  c++  java
  • list中map 的value值时间排序

    public static void main(String[] args) {
    String sys=DateUtil.getTime().substring(0,5);
    System.out.println(sys);

    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
    Calendar nowTime = Calendar.getInstance();
    nowTime.add(Calendar.MINUTE, -10);
    System.out.println(sdf.format(nowTime.getTime()));


    SimpleDateFormat format = new SimpleDateFormat("HH:mm");
    List<Map<String, Object>> alarmMaps = new ArrayList();
    HashMap<String, Object> hashMap = new HashMap<>();
    HashMap<String, Object> hashMap2 = new HashMap<>();
    HashMap<String, Object> hashMap3 = new HashMap<>();
    hashMap.put("TIME_NAME", "14:20");
    hashMap.put("TIME_TYPE", "1");
    hashMap2.put("TIME_NAME", "12:00");
    hashMap2.put("TIME_TYPE", "1");
    hashMap3.put("TIME_NAME", "9:00");
    hashMap3.put("TIME_TYPE", "1");
    alarmMaps.add(hashMap);
    alarmMaps.add(hashMap2);
    alarmMaps.add(hashMap3);
    // 注:alarmMaps里面存在 count 属性

    // String a="12:00";
    // Integer valueOf = Integer.valueOf(a);
    // System.out.println(valueOf);

    //排序 倒序
    if (alarmMaps != null && alarmMaps.size() > 1) {
    Collections.sort(alarmMaps , new Comparator<Map<String, Object>>() {
    @Override
    public int compare(Map<String, Object> o1, Map<String, Object> o2) {
    Integer o1Value = Integer.valueOf(o1.get("TIME_NAME").toString().replace(":", ""));
    Integer o2Value = Integer.valueOf(o2.get("TIME_NAME").toString().replace(":", ""));

    return o1Value.compareTo(o2Value);
    }
    });
    //14:00 <14:10-8
    if (alarmMaps.get(alarmMaps.size()-1).get("TIME_NAME").toString().replace(":", "").compareTo(sdf.format(nowTime.getTime()).replace(":", ""))<0) {
    alarmMaps.get(alarmMaps.size()-1).put("TIME_TYPE", "2");
    // a.replace("1", "2");

    }

    }

    for (Map<String, Object> map : alarmMaps) {
    System.out.println(map.get("TIME_NAME"));
    System.out.println(map.get("TIME_TYPE"));
    }
    }

    //09:00@10:30@10:00@09:30
    List<String> nums = new ArrayList<String>();
    String a="09:00@10:30@10:00@09:30";
    String[] timeArr=a.toString().split("@");

    for(int i=0;i<timeArr.length;i++){
    nums.add(String.valueOf(timeArr[i]));
    }
    Collections.sort(nums);
    String[] timeArr2 = new String[nums.size()];
    if (nums.size()>0) {
    for (int i = 0; i < nums.size(); i++) {
    timeArr2[i]=nums.get(i);
    }
    }
    }

  • 相关阅读:
    修改ZXing,使之支持条形码识别
    varchar2和varchar的区别
    “PPT Controller” 项目进度
    如何发布打包并发布自己的Android应用(APP)
    C# 新浪微博滚动抓取 WeiboGrab
    小端法与大端法(MD5疑惑解1)
    MD5的实现
    struts标签if应用
    Hibernate annotation 自增主键 与 could not initialize proxy no Session
    新的征程
  • 原文地址:https://www.cnblogs.com/jishumonkey/p/12749786.html
Copyright © 2011-2022 走看看