2014-10-05 54 views
0

我在记笔记应用程序中使用了以下代码。笔记按键排序。 TreeSet放置最早的第一个。我想做相反的事情。使用哪个类?如果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

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

相关问题