If I have a Map
like this:
HashMap map;
and I want to obtain a collection of values sorted us
TreeSet has a log(n)
time complexity guarantuee for add()/remove()/contains()
methods.
Sorting an ArrayList
takes n*log(n)
operations, but add()/get()
takes only 1
operation.
So if you're mainly retrieving, and don't sort often, ArrayList
is the better choice. If you sort often but dont retrieve that much TreeSet
would be a better choice.