I am trying to merge multiple sorted lists into one TreeSet.. And then I am thinking to apply Binary Search algorithm on that TreeSet to retrieve the element in O(log n) tim
TreeSet
is backed by a NavigableMap
, a TreeMap
specifically. Calling contains()
on a TreeSet
delegates to TreeMap.containsKey()
, which is a binary search implementation.
You can check if an object is contained in the set by using TreeSet.contains()
, but you have to have the object first. If you want to be able to look up and retrieve an object, then a Map
implementation will be better.