android - reverse the order of an array android - reverse the order of an array arrays arrays

android - reverse the order of an array


You can do this in two steps:

ArrayList<Element> tempElements = new ArrayList<Element>(mElements);Collections.reverse(tempElements);


Simple approach without implementing anything.

                ArrayList<YourObject> oldlist = new ArrayList<YourObject>();                ArrayList<YourObject> newList = new ArrayList<YourObject>();                int size = oldlist.size()-1;                for(int i=size;i>=0;i--){                    newList.add(oldlist.get(i));                }


For Android on Kotlin, this can be done with Anko's forEachReversedByIndex{} lambda operation, like this:

val tempElements = ArrayList<Element>(mElements.size)mElements.forEachReversedByIndex{tempElements.add(it)}