Here you can find the source of reverse(List
Parameter | Description |
---|---|
list | the given list |
private static void reverse(List<Object> list)
//package com.java2s; import java.util.ArrayList; import java.util.List; public class Main { private static void reverse(List<Object> list) { // original list and its copy List<Object> listCopy = new ArrayList<Object>(list.size()); for (Object object : list) { listCopy.add(object);// w ww .j a v a 2s .c o m } list.clear(); // do reverse int count = listCopy.size(); for (int i = count - 1; i >= 0; i--) { list.add(listCopy.get(i)); } // clear copy of list listCopy.clear(); } }