Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android - reverse the order of an array

I have an array of objects.

Is it possible to make a new array that is a copy of this array, but in reverse order? I was looking for something like this.

// my array ArrayList<Element> mElements = new ArrayList<Element>(); // new array ArrayList<Element> tempElements = mElements;  tempElements.reverse(); // something to reverse the order of the array 
like image 546
user401183 Avatar asked Mar 23 '11 22:03

user401183


People also ask

How do I reverse an array in Android?

This example demonstrate about How to reverse of integer array in android listview. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. In the above result, we had shown reversed array.


1 Answers

You can do this in two steps:

ArrayList<Element> tempElements = new ArrayList<Element>(mElements); Collections.reverse(tempElements); 
like image 98
Ted Hopp Avatar answered Sep 29 '22 12:09

Ted Hopp