java reverse arraylist code example
Example 1: how to reverse order of arraylist
ArrayList<Integer> arrlist = new ArrayList<Integer>();
//This is how to reverse arrlist's oringinal order.
Collections.reverse(arrlist);
//This is how to sort in a reverse order
Collections.sort(arrlist, Collections.reverseOrder());
Example 2: reverse arraylist java recursion
public ArrayList<Object> reverse(ArrayList<Object> arrayList) {
if(arrayList.size() > 1) {
Object value = arrayList.remove(0);
reverse(arrayList);
arrayList.add(value);
}
return arrayList;
}