In Java, I have a Set, and I want to turn it into a sorted List. Is there a method in the java.util.Collections package that will do this for me?
In Java, I have a Set , and I want to turn it into
Share
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.
The answer provided by the OP is not the best. It is inefficient, as it creates a new
Listand an unnecessary new array. Also, it raises ‘unchecked’ warnings because of the type safety issues around generic arrays.Instead, use something like this:
Here’s a usage example: