Java Collections.Rotate with an array doesn't work
Posted
by steve_72
on Stack Overflow
See other posts from Stack Overflow
or by steve_72
Published on 2010-05-08T17:18:24Z
Indexed on
2010/05/08
17:28 UTC
Read the original article
Hit count: 149
I have the following java code:
import java.util.Arrays;
import java.util.Collections;
public class Test {
public static void main(String[] args) {
int[] test = {1,2,3,4,5};
Collections.rotate(Arrays.asList(test), -1);
for(int i = 0; i < test.length; i++) { System.out.println(test[i]); }
}
}
I want the array to be rotated, but the output I get is
1
2
3
4
5
Why is this?
And is there an alternative solution?
© Stack Overflow or respective owner