i tried using TreeSet but it disallowing doubles is there a way to change that? if there is no way, what should i use for storing (equal and not equal) elements sorted?
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.
You can use a
List[specifically anArrayList] to hold the elements, and useCollections.sort()to sort it when you are done populating it.Sometimes a
PriorityQueueis also a good option – if what you actually need is to maintain the smallest/biggest element in the collection.If you want to maintain a sorted collection – a
SortedBag[from apache commons collections] might be what you are after. You can download a jar from here and add it to your classpath, and then just use it! Note that apache products are very commonly used, and thus are tested frequently!