Implement a method that takes an iterator from a collection and removes all elements from the collection greater than the given value.
Iterator and Iterable
Remove elements of a collection
Report a typo
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 + " "));
}
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.