I must work with a Collection, and I am not sure about using a List or a Set. This collection must be sorted, but not by the order of insertion but for another one, so each time a new item is added, a Comparator should be executed in order to reorder the Collection. So, for this reason, an ArrayList could be the best option.
Removing objects from that Collection must be possible too, furthermore, I would really appreciate using removeIf method, so a Set would be the best option here.
Getting and iterating over the Collection will be the most repeated scenario, so it must have a good performance in this scenario.
Seeing that, I think that a Set would be a good decision, however, I was thinking about converting the Set into a List when adding items, then, once the list has been resorted, converting it back to a Set. Is it bad performing? What do you think?
Thanks in advance
Collectionto be able to contain duplicate elements?ArrayListis sorted by insertion order, which you don't want. ASetis sorted each time you ad an element, so it would be the best option here.TreeSet? And why do you need aSetto useremoveIf? It is a default method of allCollections. Converting between list and set is defintely not helpful, as you'd loose the ordering (except you convert toTreeSet, of course, but then you do not need a list anyway).