IambicDiameter
IambicDiameter

Reputation: 43

Return a seperate randomized list?

I'm wondering if there is a built-in method to return a new randomized list, but all the answers I found is using Collections.shuffle(list) that shuffles the original list.

List<String> list = new LinkedList<String>();
// ...

Collections.shuffle(list); // Shuffles the original list

Is there some method that returns a new randomized list, instead of the modifying the original list?

Upvotes: 1

Views: 55

Answers (1)

Kartik
Kartik

Reputation: 7917

Create a new List and shuffle it.

List<String> list = new LinkedList<>();
List<String> newList = new LinkedList<>(list);
Collections.shuffle(newList);

Upvotes: 4

Related Questions