From eab3b8e448400229dc30eaca7e14a8ffbea5e95b Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 1 Nov 2013 20:18:33 -0500 Subject: [PATCH] Implement Collections#reverse Signed-off-by: Johannes Schindelin --- classpath/java/util/Collections.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/classpath/java/util/Collections.java b/classpath/java/util/Collections.java index f6af29ae9b..23db1872ac 100644 --- a/classpath/java/util/Collections.java +++ b/classpath/java/util/Collections.java @@ -164,6 +164,15 @@ public class Collections { return -1 - right; } + public static void reverse(List 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[] toArray(Collection collection, T[] array) { Class c = array.getClass().getComponentType();