Hip-Hop

Report a typo

You need to implement two methods using ListIterator.

  1. The method iterateOverList should iterate over the elements from the beginning to the end and add "Hop" after each "Hip".
  2. The method printList should print all elements of the list (on a new line).

Please, use ListIterators to solve this problem.

Sample Input 1:

Iterator Hip Hoi Hap Iterator Hip Hi

Sample Output 1:

Iterator
Hip
Hop
Hoi
Hap
Iterator
Hip
Hop
Hi
Write a program in Java 17
import java.util.*;
import java.util.stream.Collectors;

public class Main {

public static void iterateOverList(ListIterator<String> iter) {
// write your code here
}

public static void printList(ListIterator<String> iter) {
// write your code here
}

/* Do not change code below */
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
List<String> list = Arrays.stream(scanner.nextLine().split(" ")).collect(Collectors.toList());
iterateOverList(list.listIterator());
printList(list.listIterator());
}
}
___

Create a free account to access the full topic