020-001-013

Bidirectional Iteration with ListIterator

Hard

Problem Description

Bidirectional Iteration with ListIterator

In this problem: You will use ListIterator to iterate an ArrayList both forward and backward, and perform element addition and replacement.

Learning Objective: Understand bidirectional iteration and element manipulation with ListIterator

Overview

ListIterator extends the regular Iterator with backward iteration, element addition, and replacement capabilities.

Specifications

  • Add "A", "B", "C" to an ArrayList<String>
  • Iterate forward with ListIterator and output each element
  • Iterate backward with the same iterator and output each element
  • Create a new ListIterator, replace "B" with "B2" using set method
  • Display the final list contents

Output Format

Forward: A B C
Backward: C B A
After replace: [A, B2, C]

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