Implementing a sorted set by ordered array

May 6, 2023 · 1126 words · 6 min

A <code>Set</code> that further provides a total ordering on its elements. The elements are ordered using their natural ordering, or by a <code>Comparator</code> typically provided at sorted set creation time. The set’s iterator will traverse the set in ascending element order. Several additional operations are provided to take advantage of the ordering. (This interface is the set analogue of <code>SortedMap</code>.)

Oracle - SortedSet

Java provides a built-in SortedSet implementation, known as TreeSet. In this article, I’ll show how to implement a SortedSet by Ordered Array.