如果TreeSet排列从最旧到最新的数据,哪个类从最新到最旧排序

时间:2014-10-05 22:24:03

标签: java android sorting

我在笔记应用中有以下代码。笔记按键排序。 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());

1 个答案:

答案 0 :(得分:1)

您可以定义自己的Comparator,其行为与默认行为相反。然后在各种容器的构造函数中传递它的实例。

相关问题