gudii9
asked on
collection rotate
hi,
I was running following example
import java.util.*;
public class aaa {
public static void main(String[] args) {
List list = Arrays.asList("one Two three Four five six".split(" "));
System.out.println("List :"+list);
Collections.rotate(list, 3);
System.out.println("rotate : " + list);
}
}
from link
http://www.tutorialspoint.com/javaexamples/collection_rotate.htm
Iam getting output as
List :[one, Two, three, Four, five, six]
rotate: [Four, five, six, one, Two, three]
I have not understood meaning of output.
>> Collections.rotate(list, 3);
what above line means.
I see it is not ordered or sorted as well
Any ideas, suggestions, sample code, links, source code highly appreciated. Thanks in advance
I was running following example
import java.util.*;
public class aaa {
public static void main(String[] args) {
List list = Arrays.asList("one Two three Four five six".split(" "));
System.out.println("List :"+list);
Collections.rotate(list, 3);
System.out.println("rotate
}
}
from link
http://www.tutorialspoint.com/javaexamples/collection_rotate.htm
Iam getting output as
List :[one, Two, three, Four, five, six]
rotate: [Four, five, six, one, Two, three]
I have not understood meaning of output.
>> Collections.rotate(list, 3);
what above line means.
I see it is not ordered or sorted as well
Any ideas, suggestions, sample code, links, source code highly appreciated. Thanks in advance
ASKER
I have not understood meaning of output.
>> Collections.rotate(list, 3);
what above line means.
>> Collections.rotate(list, 3);
what above line means.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
>>>It means rotate the collection three places to the right
looks to me rotate to left.
How to visualize rotate 3 places to right
Please advise
List :[one, Two, three, Four, five, six]
rotate: [Four, five, six, one, Two, three]
looks to me rotate to left.
How to visualize rotate 3 places to right
Please advise
List :[one, Two, three, Four, five, six]
rotate: [Four, five, six, one, Two, three]
:)
The following tells you exactly how it works
http://docs.oracle.com/javase/6/docs/api/java/util/Collections.html#rotate(java.util.List,%20int)
The following tells you exactly how it works
http://docs.oracle.com/javase/6/docs/api/java/util/Collections.html#rotate(java.util.List,%20int)