java - How to sort dates in a List -
java - How to sort dates in a List -
how can sort dates within list?
i have read can achieved using treemap, sorted , navigable map organizes elements in self-balancing binary tree. expensive.
my question - best , efficient way accomplish result?
it depends. if want have "always sorted" container treeset friend. adding element treemap o(log(n)) - (very good, faster linear).
if need sort 1 time (no adding elements later), set arraylist , utilize sort() method. optimal - o(n log(n))
update:
as jb nizet mentioned in comment, set (treeset) cannot contain duplicates. list (arraylist) can. if performance of import , there lot of elements , need store sorted elements allowing duplicates, can store in treeset, need implement counting (add()
element.count++
, , remove()
element.count--
example).
java sorting date
Comments
Post a Comment