Predicate
is a functional interface that allows you to test objects of a given
type. Given Predicate
, removeIf
will remove all elements
which return true for this predicate.
When trying to use the removeIf()
method, to test a list that receives a Predicate, I'm having the exception quoted in the title, does anyone know why?
Code:
Predicate<Usuario> predicado = new Predicate<Usuario>() {
public boolean test(Usuario u) {
return u.getPontos() > 160;
}
};
List<Usuario> lista = Arrays.asList(usuario,usuario1, usuario2, usuario3);
lista.removeIf(predicado);
lista.forEach(u -> System.out.println(u));
But when I do this, it prints without error:
Predicate<Usuario> predicado = new Predicate<Usuario>() {
public boolean test(Usuario u) {
return u.getPontos() > 160;
}
};
List<Usuario> lista = new ArrayList<Usuario>();
lista.add(usuario2);
lista.add(usuario3);
lista.add(usuario1);
lista.add(usuario);
lista.removeIf(predicado);
lista.forEach(u -> System.out.println(u));
Does anyone know why the exception thrown, when I pass the users inside:
Arrays.asList();