Is there a way to sort a Set?
I have a Set of double and I am looking for a way to sort them.
I understand it is very easy using List, but something using Set is getting a bit tricky to me.
Any inputs would be great help.
You should put them into TreeSet. TreeSet is a SortedSet implementation which orders the elements according to the natural ordering.
TreeSet accepts objects which implements Comparable which defines the sort order. Double objects can be put into TreeSet since they implement Comparable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With