簡體   English   中英

如果TreeSet按從最舊到最新的順序排列數據,哪個類將它們從最新到最舊的順序排序

[英]If TreeSet arranges data from oldest to newest which class orders them from newest to oldest

我在筆記應用程序中有以下代碼。 注釋按鍵排序。 TreeSet將最舊的放在首位。 我想相反。 使用哪個班級?

    //retrieve data, map unordered data collection with a key and a value
    Map<String, ?> notesMap = notePrefs.getAll();
    //get a list of all the keys of the notes, keySet-return all Keys without order, TreeSet-sorts data
    SortedSet<String> keys =new TreeSet<String>(notesMap.keySet());

您可以定義自己的Comparator ,其行為與默認情況相反。 然后在各種容器的構造函數中傳遞它的實例。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM