logo CodeStepByStep logo

removeEvens

Language/Type: Java Set Collections Iterator
Related Links:

Write a method named removeEvens that accepts a Set of integers as a parameter and removes the even values from the set, returning those values as a new set. The new set's even values should be ordered in ascending numerical order. For example, if a set set1 contains [0, 17, 16, 7, 10, 14, 13, 12], and we make the following call:

Set<Integer> set2 = removeEvens(set1);

Then after the call set1 and set2 would contain the following values:

set1: [17, 7, 13]
set2: [0, 10, 12, 14, 16]
Method: Write a Java method as described, not a complete program or class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.