• JAVA时间数组中取最大最小日期


    public static void main(String[] args) {
            String [] dateArray = {"2013-04-01","2013-04-08","2013-04-28","2013-04-08", "2013-11-11"};
            showMaxDate(dateArray);
        }
    
        private static String showMaxDate(String[] dateArray) {
            Map<String, Integer> dateMap = new TreeMap<String, Integer>();
            int i, arrayLen;
            arrayLen = dateArray.length;
            for(i = 0; i < arrayLen; i++){
                String dateKey = dateArray[i];
                if(dateMap.containsKey(dateKey)){
                    int value = dateMap.get(dateKey) + 1;
                    dateMap.put(dateKey, value);
                }else{
                    dateMap.put(dateKey, 1);
                }
            }
            Set<String> keySet = dateMap.keySet();
            String []sorttedArray = new String[keySet.size()];
            Iterator<String> iter = keySet.iterator();
            int index = 0;
            while (iter.hasNext()) {
                String key = iter.next();
                //    System.out.println(key + ":" + dateMap.get(key));
                sorttedArray[index++] = key;
            }
            int sorttedArrayLen = sorttedArray.length;
            System.out.println("最小日期是:" + sorttedArray[0] + "," +
                    " 天数为" + dateMap.get(sorttedArray[0]));
            System.out.println("最大日期是:" + sorttedArray[sorttedArrayLen - 1] + "," +
                    " 天数为" + dateMap.get(sorttedArray[sorttedArrayLen - 1]));
            return sorttedArray[sorttedArrayLen - 1];
        }
  • 相关阅读:
    「CF505E」 Mr. Kitayuta vs. Bamboos
    「CF1438D」 Powerful Ksenia
    Kruskal重构树
    20210528模拟赛总结
    20210527模拟赛总结
    20210526模拟赛总结
    20210525模拟赛总结
    CF #722 Div2题解
    洛谷P3652 csh和zzy的战争 题解
    [清华集训2012]模积和 题解
  • 原文地址:https://www.cnblogs.com/kevinZhu/p/14595680.html
Copyright © 2020-2023  润新知