什么是最简单的方法来反转ArrayList?

问题:

什么是最简单的方法来反转这个ArrayList?

ArrayList aList = new ArrayList();

//Add elements to ArrayList object
aList.add("1");
aList.add("2");
aList.add("3");
aList.add("4");
aList.add("5");

while (aList.listIterator().hasPrevious())
  Log.d("reverse", "" + aList.listIterator().previous());

回答:

Collections.reverse(aList);

示例(Reference):

ArrayList aList = new ArrayList();
//Add elements to ArrayList object
aList.add("1");
aList.add("2");
aList.add("3");
aList.add("4");
aList.add("5");
Collections.reverse(aList);
System.out.println("After Reverse Order, ArrayList Contains : " + aList);

 
 
Code问答: http://codewenda.com/topics/python/
Stackoverflow: What is the Simplest Way to Reverse an ArrayList?

*转载请注明本文链接以及stackoverflow的英文链接

发表评论

电子邮件地址不会被公开。 必填项已用*标注

91 − = 81