Reverse an ArrayList

 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.
posted @ 2015-12-31 05:51  Hygeia  阅读(174)  评论(0编辑  收藏  举报