- 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
How to shuffle a List in Java
First, create an Integer array −
Integer[] strArray = new Integer[] { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };
Now, convert it into a List −
List<Integer>list = Arrays.asList(strArray);
Use Collections to shuffle as shown below −
Collections.shuffle(list);
Example
import java.util.Arrays; import java.util.Collections; import java.util.List; public class Demo { public static void main(String args[]) { Integer[] strArray = new Integer[] { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 }; List<Integer>list = Arrays.asList(strArray); System.out.println("List = "+list); Collections.shuffle(list); System.out.println("Shuffled List = "+list); } }
Output
List = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100] Shuffled List = [100, 90, 40, 70, 20, 10, 80, 30, 60, 50]
- Related Articles
- Shuffle or Randomize a list in Java
- How to shuffle a list of objects in Python?
- Java Program to shuffle an array using list
- how to shuffle a 2D array in java correctly?
- How to shuffle an array in Java?
- How to randomize and shuffle array of numbers in Java?
- How to shuffle a std::vector in C++
- Java Program to Shuffle the Elements of a Collection
- How to randomize (shuffle) a JavaScript array?
- How to do Butterfly Shuffle in JavaScript?
- How to copy a list to another list in Java?
- How to shuffle an array in a random manner in JavaScript?
- How to Clone a List in Java?
- How to iterate a list in Java?
- Shuffle elements of ArrayList with Java Collections

Advertisements