首页 > 其他分享 >多个日期,找最大最小日期

多个日期,找最大最小日期

时间:2022-10-24 16:44:50浏览次数:89  
标签:String 多个 int dateMap 最小 日期 dateKey sorttedArray


    //最大最小日期
    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();
            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];
    }

 

标签:String,多个,int,dateMap,最小,日期,dateKey,sorttedArray
From: https://www.cnblogs.com/w852894903/p/16821929.html

相关文章