- 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
Java Program to shuffle an array using list
Let us first create a string array and convert it to a list. After that, the shuffle would be performed.
Following is the string array −
String str[] = {"A", "B", "C", "D", "E"};
Convert the string array to list −
List<String>list = Arrays.asList(str);
Now shuffle the array −
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) { String str[] = {"A", "B", "C", "D", "E"}; List<String>list = Arrays.asList(str); Collections.shuffle(list); System.out.println("Shuffled the array using List = "+list.toString()); } }
Output
Shuffled the array using List = [C, B, E, D, A]
- Related Articles
- How to shuffle an array in Java?
- Shuffle an Array using STL in C++
- Golang program to shuffle the elements of an array
- How to shuffle a List in Java
- Java program to convert a list to an array
- Java program to convert an array to a list
- Shuffle an Array in Python
- Java Program to Remove Duplicates from an Array List
- Shuffle or Randomize a list in Java
- Java Program to Sort Array list in an Ascending Order
- How to convert an Array to a List in Java Program?
- how to shuffle a 2D array in java correctly?
- Java Program to Shuffle the Elements of a Collection
- How to randomize and shuffle array of numbers in Java?
- Java Program to Get First and Last Elements from an Array List

Advertisements