Reverse an ArrayList

mac2022-06-30  70

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.

转载于:https://www.cnblogs.com/hygeia/p/5090548.html

最新回复(0)