Java TreeMap headMap(toKey,inclusive) Method Example

Previously we have seen the usage of  headMap(K toKey) method of java.util.TreeMap class which returns the view portion of this map whose keys are strictly less than toKey. Whereas headMap(K toKey,boolean inclusive) method returns a view of the portion of this map whose keys are less than (or equal to, if inclusive is true)toKey.
[Read more…]

Java TreeSet tailSet(E fromElement, boolean inclusive) Method Example

The tailSet(E fromElement) method of  java.util.TreeSet class returns a view of the portion of this set whose elements are greater than or equal (if inclusive is true) to fromElement. The returned set is backed by this set, so changes in the returned set are reflected in this set, and vice-versa. The returned set supports all optional set operations that this set supports.

[Read more…]