码迷,mamicode.com
首页 > 其他好文 > 详细

Reverse an ArrayList

时间:2015-12-31 07:15:04      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:

 public ArrayList<Integer> reverse(ArrayList<Integer> list) {
       for(int i = 0, j = list.size() - 1; i < j; i++) 
       {
          list.add(i, list.remove(j));
       }
       return list;
}

remove(int index)

Removes the element at the specified position in this list. Return the element.
 
add(E e)
Appends the specified element to the end of this list.
 
add(int index, E element)
Inserts the specified element at the specified position in this list.

Reverse an ArrayList

标签:

原文地址:http://www.cnblogs.com/hygeia/p/5090548.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!