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

Connected

Exercise

Undo last action in a text editor

Many text editors allow users to navigate backward through changes and insert missing words when needed. Using ListIterator, you can move backward through a list of actions and insert corrections where necessary.

In this exercise, you will traverse a list of words in reverse, and if you find "error", you will insert correction before it, simulating an undo operation in a text editor.

Instructions

100 XP
  • Create a ListIterator object for the textHistory list, starting from the end.
  • Check if more previous elements are available in textHistory list.
  • Retrieve the previous element and move ListIterator backward
  • Insert new element correction before element error