机器人 - 扭转数组的顺序 [英] android - reverse the order of an array
本文介绍了机器人 - 扭转数组的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有对象的数组。
是否有可能使一个新的数组,它是这个数组的一个副本,但以相反的顺序? 我一直在寻找这样的事情。
//我的数组
的ArrayList&其中;组件> mElements =新的ArrayList<组件>();
//新数组
的ArrayList&其中;组件> tempElements = mElements;
tempElements.reverse(); //东西扭转排列的顺序
解决方案
您可以分两步做到这一点:
的ArrayList<组件> tempElements =新的ArrayList<组件>(mElements);
Collections.reverse(tempElements);
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
解决方案
You can do this in two steps:
ArrayList<Element> tempElements = new ArrayList<Element>(mElements);
Collections.reverse(tempElements);
这篇关于机器人 - 扭转数组的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文