Remove elements of a collection

Report a typo

Implement a method that takes an iterator from a collection and removes all elements from the collection greater than the given value.

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

public class Main {

public static void removeElementsGreaterThanValue(Iterator<Long> iterator, Long val) {
// write your code here
}

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

Create a free account to access the full topic