久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

排序鍵是哈希圖中的日期條目

Sort keys which are date entries in a hashmap(排序鍵是哈希圖中的日期條目)
本文介紹了排序鍵是哈希圖中的日期條目的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個 hashMap,它具有以下值作為鍵 value(sql date , integer) 對:

I have a hashMap which has the following values as key value(sql date , integer) pairs:

a.put("31-05-2011",67);
a.put("01-06-2011",89);
a.put("10-06-2011",56);
a.put("25-05-2011",34);

當我嘗試使用基于鍵對 hashMap 進行排序時:Map modified_a=new TreeMap(a);并顯示按鍵如下:

when i try to sort the hashMap based on the keys using : Map modified_a=new TreeMap(a); and display the keys it is as follows :

01-06-2011,10-06-2011,25-05-2011, 31-05-2011

但我希望將鍵排序為

31-05-2011,25-05-2011,01-06-2011 ,10-06-2011

我可以看到這些值是根據前 2 位數字(即日期值)進行排序的,但我還需要考慮月份值并首先根據月份進行排序,然后每個月對相應的日期進行排序.有什么線索嗎??

I can see that the values are being sorted based on the first 2 digits( which is the date value) but I need the month value to also be considered and sort based on months first and then for each month sort the corresponding days. Any clues ??

推薦答案

可以用like

Map<Date, Integer> m = new HashMap<Date, Integer>(); 

    DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");

    m.put(new java.sql.Date(dateFormat.parse("31-05-2011").getTime()),67);
    m.put(new java.sql.Date(dateFormat.parse("01-06-2011").getTime()),89);
    m.put(new java.sql.Date(dateFormat.parse("10-06-2011").getTime()),56);
    m.put(new java.sql.Date(dateFormat.parse("25-05-2011").getTime()),34);


    Map<Date, Integer> m1 = new TreeMap(m);
    DateFormat df = new SimpleDateFormat("dd/MM/yyyy");

    for (Map.Entry<Date, Integer> entry : m1.entrySet())
    {
        System.out.println(df.format(entry.getKey()));
    }

這篇關于排序鍵是哈希圖中的日期條目的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Convert List of Strings into Map using Java-8 Streams API(使用 Java-8 Streams API 將字符串列表轉換為 Map)
Getting data from JSON(從 JSON 獲取數據)
java linkedhashmap iteration(javalinkedhashmap迭代)
Converting a list of objects to Map(將對象列表轉換為 Map)
Create a HashMap with a fixed Key corresponding to a HashSet. point of departure(用一個固定的Key對應一個HashSet創建一個HashMap.出發點)
HttpMessageConverter exception : RestClientException: Could not write request: no suitable HttpMessageConverter found(HttpMessageConverter 異常:RestClientException:無法寫入請求:找不到合適的 HttpMessageConverter) - IT屋-程序員
主站蜘蛛池模板: 久久久精品综合 | 日韩在线一区二区三区 | 亚洲一二三区在线观看 | 综合久 | 午夜免费福利影院 | 久久国产精品一区二区三区 | 欧美三级电影在线播放 | 欧美日韩综合一区 | 日韩在线观看中文字幕 | 成人不卡视频 | 欧美一区二区大片 | 高清免费av | 日日干干夜夜 | 欧美色综合网 | 日韩精品一区二区三区在线观看 | 国产日韩欧美一区二区 | 91激情视频 | 91tv在线观看 | 欧美一级片在线观看 | 国产一区二区三区久久久久久久久 | 国产视频一区二区在线观看 | 欧美一区在线视频 | 国产精品美女一区二区三区 | 欧美成年网站 | 电影午夜精品一区二区三区 | 亚洲乱码一区二区三区在线观看 | 精久久久久 | 欧美一区二区三区大片 | 午夜一区二区三区在线观看 | 成人精品鲁一区一区二区 | 天天搞天天操 | 黄在线免费观看 | 亚洲精品一区二区在线观看 | 秋霞a级毛片在线看 | 在线免费毛片 | 日韩电影一区二区三区 | 999精品网| 日韩资源 | 久久精品aaa| 中文字幕一区二区三区精彩视频 | 国产精品一区二区免费 |