summaryrefslogtreecommitdiff
path: root/java/util/Collections.java
diff options
context:
space:
mode:
authorJochen Hoenicke <jochen@gnu.org>2000-01-31 09:56:48 +0000
committerJochen Hoenicke <jochen@gnu.org>2000-01-31 09:56:48 +0000
commit57376e0f0f5f0a58a7e886eaf1b62f32b84db540 (patch)
tree219265bda6e4a66b130feb642152adf9f84674f5 /java/util/Collections.java
parent760341097d6d9fd8db182d948e3d524ad6f21435 (diff)
downloadclasspath-57376e0f0f5f0a58a7e886eaf1b62f32b84db540.tar.gz
fixed a bug in shuffle (it was duplicating some entries, removing others)
Diffstat (limited to 'java/util/Collections.java')
-rw-r--r--java/util/Collections.java12
1 files changed, 8 insertions, 4 deletions
diff --git a/java/util/Collections.java b/java/util/Collections.java
index 4db8776cb..6ed996024 100644
--- a/java/util/Collections.java
+++ b/java/util/Collections.java
@@ -470,13 +470,17 @@ public class Collections {
// Obtain a random position to swap with. nextIndex is used so that the
// range of the random number includes the current position.
- int swap = r.nextInt(i.nextIndex());
+ int swap = r.nextInt(i.nextIndex());
// Swap the swapth element of the array with the next element of the
// list.
- Object o = i.previous();
- i.set(a[swap]);
- a[swap] = o;
+ Object o = a[swap];
+ a[swap] = a[i.previousIndex()];
+ a[i.previousIndex()] = o;
+
+ // Set the element in the original list accordingly.
+ i.previous();
+ i.set(o);
}
}