1. Learn
  2. /
  3. Courses
  4. /
  5. Input/Output and Streams in Java

Connected

Exercise

Filtering large numbers

In many applications, filtering data is an essential step in processing large datasets. For example, in financial applications, age-restricted platforms, or performance tracking systems, you may need to remove values above a certain threshold. In this exercise, you will practice using an Iterator to traverse a collection and remove numbers greater than 25, ensuring it has only relevant values.

All the necessary classes from java.util have been imported for you.

Instructions

100 XP
  • Create an Iterator for the created set numbers.
  • Use a while loop to check if the set numbers has more elements.
  • Retrieve the next element and assign to a new variable current.
  • If the number is greater than 25, remove it.