Hi!
I am typing my own example of TreeSet.
Basically I have Objects of type Item which have a name of type
String and weight of type int. :
Well, if I create a TreeSet and I start to add objects they are sorted by name as I specified in the compareTo method.
At this point my question is: How can I sort the treeSet using for example the weight?
My approach is as follows:
- I have created a comparator and I am trying to sort the TreeSet with it.
But I don't know how to sort the TreeSet without creating a new one.... I got the items sorted by weight using an array:
How can I sort the treeSet without having to create a new one?
Thanks