Let’s learn TreeSet headSet(E toElement) method in java. TreeSet headSet(E toElement) method in java headSet(E toElement) method of TreeSet class returns a view of the portion of this set whose elements are strictly less than toElement. Syntax: public SortedSet<E> headSet(E toElement) Parameters: toElement high endpoint (exclusive) of the returned set. Throws: ClassCastException – if toElement…

Read More TreeSet headSet(E toElement) method in java

Let’s learn TreeSet headSet(E toElement, boolean inclusive) method in java. TreeSet headSet(E toElement, boolean inclusive) method in java headSet(E toElement, boolean inclusive) method of TreeSet class returns a view of the portion of this set whose elements are less than(or equal to, if inclusive is true) toElement. Syntax: public NavigableSet<E> headSet(E toElement, boolean inclusive) Parameters:…

Read More TreeSet headSet(E toElement boolean inclusive) method in java

Let’s learn TreeSet tailSet(E fromElement, boolean inclusive) method in java. TreeSet tailSet(E fromElement, boolean inclusive) method in java tailSet(E fromElement, boolean inclusive) method of TreeSet class returns a view of the portion of this set whose elements are greater than (or equal to, if inclusive is true) fromElement. Syntax: public NavigableSet<E> tailSet(E fromElement, boolean inclusive)…

Read More TreeSet tailSet(E fromElement boolean inclusive) method in java

Let’s learn TreeSet tailSet(E fromElement) method in java. TreeSet tailSet(E fromElement) method in java tailSet(E fromElement) method of TreeSet class returns a view of the portion of this set whose elements are greater than or equal to fromElement. Syntax: public SortedSet<E> tailSet(E fromElement) Parameters: fromElement low endpoint (inclusive) of the returned set. Throws: ClassCastException –…

Read More TreeSet tailSet(E fromElement) method in java

Let’s learn TreeSet subSet(E fromElement, E toElement) method in java. TreeSet subSet(E fromElement, E toElement) method in java subSet(E fromElement, E toElement) method of TreeSet class returns a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive. Syntax: public SortedSet<E> subSet(E fromElement, E toElement) Parameters: fromElement low endpoint…

Read More TreeSet subSet(E fromElement E toElement) method in java

Let’s learn TreeSet subSet() method in java. TreeSet subSet() method in java subSet() method of TreeSet class returns a view of the portion of this set whose elements range from fromElement to toElement. Syntax: public NavigableSet<E> subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive) Parameters: fromElement low endpoint of the returned set. fromInclusive true if…

Read More TreeSet subSet() method in java

Let’s learn TreeSet size() method in java. TreeSet size() method in java size() method of TreeSet class returns the number of elements in this set (its cardinality). Syntax: public int size() Now let’s see example on TreeSet size() method. import java.util.TreeSet; public class TreeSetSizeMethodExample { public static void main(String[] args) { TreeSet<String> ts = new…

Read More TreeSet size() method in java

Let’s learn TreeSet last() method in java. TreeSet last() method in java last() method of TreeSet class returns the last (highest) element currently in this set. Syntax: public E last() Throws: NoSuchElementException – if this set is empty. Now let’s see example on TreeSet last() method. import java.util.TreeSet; public class TreeSetLastMethodExample { public static void…

Read More TreeSet last() method in java