久久久久久久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屋-程序員
主站蜘蛛池模板: 黄色网一级片 | 午夜国产一级 | 国产精品www| 亚洲精品高清视频 | 久久久精品影院 | 综合中文字幕 | 水蜜桃亚洲一二三四在线 | 亚洲精品乱码 | 激情欧美一区二区三区 | 九九av| 国产精品无码专区在线观看 | 欧美在线免费 | 国产区精品在线观看 | 国产一二三视频在线观看 | 成人欧美一区二区三区在线观看 | 91久久国产综合久久 | 欧美日韩高清 | 欧美一级在线 | 五月香婷婷| 91精品国产一区二区三区 | 久久久久国产精品午夜一区 | 在线观看成人精品 | 激情国产| 黄色毛片在线看 | 天天宗合网 | 九九伦理电影 | 久久久久久国模大尺度人体 | 黄色大片免费看 | 国产清纯白嫩初高生在线播放视频 | 毛片网络| 天堂综合网久久 | 天天干狠狠干 | 日韩在线观看中文字幕 | 日日骑| 黄色一级大片在线免费看产 | 成人午夜免费视频 | a级片网站 | 久久精品一区 | 欧美日韩1区2区 | 在线视频国产一区 | 综合精品久久久 |