Java sorted collection with a count-based sublist -
we know can use
collections.sort
to sort list after elements inserted.
but if elements inserted once time, maybe sortedmap
more effective?
though, sortedmap
lack sublist
method.
what need sortedmap
can insert small amount of elements many times, , can 1~1000 sublist top-down comparator
interface.
any suggestion?
i think sortedset
navigableset
in turn has methods subset
, tailset
, headset
, ceiling
, floor
kind of problems.
so like:
sortedset<integer> set = new treeset<>(arrays.aslist(0,1,2,3,4,5,6,7,8,9)); sortedset<integer> subset = set.subset(3,7); system.out.println(subset); //[3,4,5,6]
obviously can create treeset
whatever comparator
want, , perform searches in order find more convenient.
comparator<integer> reverse = collections.reverseorder(); sortedset<integer> set = new treeset<>(reverse); //same thing here
Comments
Post a Comment