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()?
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".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With