Suppose an external collection has the following two methods: add(BusiessObject) to the end and remove(BusinessObject). Now, I know the order of objects I want and I want to make sure that the external collection maintains that order. So, if I start with BO1, BO2, BO3, then if I remove BO2 and add it again, I want to make sure that the order will be the same.
I was thinking of keeping my list of present items, in order I want, and upon every insertion, I would clear the external list, and then add all elements from my sorted list. Any other ideas?
If you don’t have control over the external collection, I think that the solution that you proposed is the way. To keep your Java side collection ordered, you don’t need to keep calling the sort method, but just use a ordered collection like TreeSet or TreeMap, or any collection that implements SortedSet or SortedMap, to store your data. You still need to implement Comparable or Comparator as @AdelBoutros said.
By the way, I’m curious about your external collection. May you say what is it? Maybe we can think in another approach if we know what it is.