TreeSet Exercise Solution

Let's look at the solution of TreeSet exercises.

Problem 1: Numbers greater than 50

Given an array of numbers, find all the numbers that are greater than 50.

Solution

There is a tailSet(E e) method in the TreeSet class that returns a set of all the elements that are greater than the provided element. We will add all the elements from the array to a TreeSet. Then we will find all the elements greater than 50 using the tailSet() method.

Get hands-on with 1400+ tech skills courses.