The bottom layer of TreeSet and TreeMap in java is a red- black tree
The operation of accessing elements internally is O(logN), while ordinary HashMap accessing elements is O(1)
However, the internal elements of TreeSet and TreeMap are sorted . When you need to find elements of certain sizes and output elements in order, the results are ideal.
TreeMap is a sorted version of HashMap of internal elements
TreeSet is implemented by encapsulating HashSet member variables