import java.util.*;
public class MyClass {
public static <T> void remove(ArrayList<T> al, int n) {
Iterator it = al.iterator();
while (it.hasNext()) {
int val = (Integer)it.next();
if (val > n)
it.remove();
}
}
public static void main(String args[]) {
ArrayList<Integer> al = new ArrayList<>(Arrays.asList(5, 3, 8, 5, 0, 1, 99, 7, 4, 2));
System.out.println(al);
int N = 5;
remove(al, N);
System.out.println(al);
}
}
/*
run:
[5, 3, 8, 5, 0, 1, 99, 7, 4, 2]
[5, 3, 5, 0, 1, 4, 2]
*/