Answers for "reverse elements in an arraylist java"

5

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());
Posted by: Guest on September-06-2020
0

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;
}
Posted by: Guest on November-11-2020

Code answers related to "reverse elements in an arraylist java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language