Reputation: 43
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
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