Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - Google App Engine - Sort ArrayList<Object> without using Collections.sort()

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! ^^

like image 821
maxdelia Avatar asked Apr 25 '26 18:04

maxdelia


1 Answers

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);
like image 168
Kumar Vivek Mitra Avatar answered Apr 27 '26 08:04

Kumar Vivek Mitra