Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
I need to sort an ArrayList and i can't use Collections.sort(), because Google App Engine's Java runtime environment doesn't support it. How can I do? Thank
I need to sort an ArrayList and i can't use Collections.sort(), because Google App Engine's Java runtime environment doesn't support it. How can I do? Thanks! ^^
Does Google App Engine support TreeSet? If so, assuming there are no duplicates and the elements are Comparable, use a TreeSet.
TreeSet
Comparable
List list = your ArrayList List sortedList = new ArrayList(new TreeSet(list));
You can also supply a Comparator to TreeSet if the elements aren't Comparable. I left generics left out for simplicity.
Comparator
If your ArrayList has NO DUPLICATE VALUES..... and i am assuming even if it had, you didnt wanted to have redundant data..so its better to use TreeSet and Comparator together...
Eg:
ArrayList<MyObject> arr = new ArrayList<MyObject>(); TreeSet<MyObject> t = new TreeSet<MyObject>(Comparator c); t.addAll(arr);
谷歌应用引擎支持TreeSet吗?如果是这样,假设没有重复并且元素是Comparable,请使用TreeSet.
如果元素不是,您也可以提供Comparatorto 。为简单起见,我忽略了泛型。TreeSetComparable