DummyBeginner :
I'm going to find a class in a list of Classes (List<Class<?>>
) with java streams:
Class cls = classList.stream().filter(clazz -> clazz.getName().startsWith("MyName")).findAny().orElse(null);
A class with the name MyNameClass
exists in the list, but the value of cls
is null at the end. Is there anything wrong in the filter()
?
DDovzhenko :
You should use .getSimpleName
, .getName
returns fully qualified name of the class with package in it. For example, String.class.getName()
returns "java.lang.String".