Reversed list

Report a typo
Implement a method that takes an instance of ListIterator and creates a new list in the reversed order. The given iterator is on the first element of a list. Use only the iterator to write a solution.

Sample Input 1:

1001 1002 1001 1003

Sample Output 1:

1003 1001 1002 1001
Write a program in Java 17
import java.util.*;
import java.util.stream.Collectors;

public class Main {

public static <T> List<T> createReversedListByIterator(ListIterator<T> iterator) {
List<T> list = new ArrayList<>();

// write your code here

return list;
}

/* Do not change the code below */
public static void main(String[] args) {
final Scanner scanner = new Scanner(System.in);
final List<Integer> list = Arrays.stream(scanner.nextLine().split("\\s+"))
.map(Integer::parseInt)
.collect(Collectors.toList());
createReversedListByIterator(list.listIterator())
.forEach(e -> System.out.print(e + " "));
}
}
___

Create a free account to access the full topic