Rotate elements of a collection in Java
Description
The following code shows how to rotate elements of a collection.
Example
// w ww .j a va2 s.c o m
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class Main {
public static void main(String[] args) {
List numbers = new ArrayList();
for (int i = 0; i < 25; i++) {
numbers.add(i);
}
System.out.println(Arrays.toString(numbers.toArray()));
Collections.rotate(numbers, 10);
System.out.println(Arrays.toString(numbers.toArray()));
}
}
The code above generates the following result.