Finding the max number

Report a typo
Implement a method that returns the max number in a collection using the iterator. It's guaranteed the collection always has at least one element.

Sample Input 1:

1 3 8 4 5

Sample Output 1:

8
Write a program in Java 17
import java.util.*;
import java.util.stream.Collectors;

public class Main {

public static int findMaxByIterator(Iterator<Integer> iterator) {
// write your code here
}

/* Do not change 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());

System.out.println(findMaxByIterator(list.iterator()));
}
}
___

Create a free account to access the full topic