- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Rotate a List in Java
To rotate a list in Java, let us first create a List and add elements −
List < Integer > list = new ArrayList < Integer > (); list.add(5); list.add(10); list.add(15); list.add(20); list.add(25); list.add(30); list.add(35); list.add(40); list.add(45);
Now, rotate the list −
Collections.reverse(list);
Example
import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Demo { public static void main(String args[]) { List<Integer>list = new ArrayList<Integer>(); list.add(5); list.add(10); list.add(15); list.add(20); list.add(25); list.add(30); list.add(35); list.add(40); list.add(45); System.out.println("Initial list = "+list); Collections.reverse(list); System.out.println("List after rotation = "+list); } }
Output
Initial list = [5, 10, 15, 20, 25, 30, 35, 40, 45] List after rotation = [45, 40, 35, 30, 25, 20, 15, 10, 5]
- Related Articles
- Java Program to Rotate Elements of a List
- Rotate List in C++
- Python - Ways to rotate a list
- Rotate elements of a collection in Java
- Rotate List Left by K in C++
- Python Program to Rotate Elements of a List
- Python program to right rotate a list by n
- Program to rotate a linked list by k places in C++
- How can we rotate a JLabel text in Java?
- Rotate the matrix 180 degree in Java?
- Java Program to Rotate Matrix Elements
- Java Program to Rotate an Image
- Write a program in Java to rotate a matrix by 90 degrees in anticlockwise direction
- Python program to rotate doubly linked list by N nodes
- JavaScript Program for Rotate Doubly linked list by N nodes

Advertisements