Implement Collections#reverse

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin 2013-11-01 20:18:33 -05:00
parent a61bcf824f
commit eab3b8e448

View File

@ -164,6 +164,15 @@ public class Collections {
return -1 - right;
}
public static <T> void reverse(List<T> list) {
int ascending = 0, descending = list.size() - 1;
while (ascending < descending) {
T tmp = list.get(ascending);
list.set(ascending++, list.get(descending));
list.set(descending--, tmp);
}
}
static <T> T[] toArray(Collection collection, T[] array) {
Class c = array.getClass().getComponentType();