020-001-010

Conditional Element Removal with ArrayList and Iterator

Hard

Problem Description

Conditional Element Removal with ArrayList and Iterator

In this problem, you will implement a method removeEvens that safely removes even numbers from a range of integers using an Iterator and returns the remaining odd numbers as a comma-separated string.

Learning Objective: Understand safe element removal using Iterator and advanced ArrayList operations

Specification

Class Design

  • Method: public static String removeEvens(int start, int end)
    • Add integers from start to end to an ArrayList<Integer>
    • Use an Iterator to safely remove even numbers
    • Return the remaining elements joined by ", "

Examples

removeEvens(1, 8) → "1, 3, 5, 7"
removeEvens(10, 15) → "11, 13, 15"

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up