logo CodeStepByStep logo

removeEvens

Language/Type: Java List Collections Iterator
Related Links:

Write a method named removeEvens that accepts a List of integers as a parameter and removes the even values from the list, returning those values as a new list. The new list's even values should be ordered in the same relative order as they appeared in the original list. For example, if a list list1 contains [0, 17, 16, 7, 10, 14, 13, 12], and we make the following call:

List<Integer> list2 = removeEvens(list1);

Then after the call list1 and list2 would contain the following values:

list1: [17, 7, 13]
list2: [0, 16, 10, 14, 12]
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.