的列表的順序這是我有:排序對象的列表與對象ID
class Person {
Integer id;
String name;
}
// A list of persons:
List<Person> persons
// Now I have something like this:
List<Integer> ids // where the ids are stored in an specific order
基本上我以相同的順序,如IDS想排序的人員名單。
有沒有更好的方法,然後像兩個循環一樣使用並創建一個新的Person-List?
問候& & TIA
noircc
複雜性是什麼? – 2012-04-25 16:13:26
Collections.sort是O(nlogn),但是對於每個比較都有兩個O(n)索引查找,所以不能非常有效,但至少沒有創建臨時收藏。 – dogbane 2012-04-25 16:36:31
恩,謝謝! – noircc 2012-04-26 07:43:20