List 原地逆转

public static <E> List<E> reverse(List<E> list) {
	if (list != null && !list.isEmpty()) {
		int size = list.size();
		for (int i = 0, n = size/2; i < n; i++) {
			E temp = list.get(i);
			list.set(i, list.get(size - 1 -i));
			list.set((size - 1 -i), temp);
		}
	}
	return list;
}

 

你可能感兴趣的:(list)