What will prompt one to use this method?
Update : I see the point now. I like the reason of Uri “Shuffling is not a trivial algorithm”. That is quite true.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There can be many reasons one would want to randomly shuffle an ordered sequence of elements. For instance, a deck of cards.
Shuffling is not a trivial algorithm, just as sorting isn’t – So it is common enough to necessitate a library function.
As to why a list – obviously it has to be an ordered collection, thus not any general Collection. Only list and its subtypes are guaranteed to be ordered. The Collections class does not provide operations for arrays, but you could (and probably should, for performance) pass an ArrayList to this method.