Java Collections rotate() MethodThe rotate() method of Java Collections class is used to rotate the elements in the specified list by a given distance. SyntaxFollowing is the declaration of rotate() method: Parameter
ReturnsThe rotate() method does not return anything. ExceptionsUnsupportedOperationException- It throws this type of exception if the specified list or its list-iterator does not support the set operation. Compatibility VersionJava 1.4 and above Example 1Test it NowOutput: Original List : [Java, Python, Cobol, Perl, Android] Rotated List: [Cobol, Perl, Android, Java, Python] Example 2Test it NowOutput: Value Before Rotation: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Value After Rotation: [6, 7, 8, 9, 10, 1, 2, 3, 4, 5] Example 3Test it NowOutput: Original Array: [10, 20, 30, 40, 50] Modified Array: [30, 40, 50, 10, 20] Next TopicJava Collections Class |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India