Earlier quoted context omitted.
That’s what disappoints me in modern Java. There is practically no ifs. It makes it inaccessible to beginners on the project, and the streams are about twice as slow… just because devs think they are more clever if they pile 7 “.map()” to transform a list. list.stream().filter(Objects::nonNull).map(User::getUsername).filter(Objects::nonNull).filter(name -> name.contains(searchString)).map(name -> “We have found your…
the two snippets you posted do different things In a list John Jonhatan Joy searching for "Jo" returns all three of them in the first example, it stops when the first has been found in the second. Start including the tedious bits about adding found items to the list and the waste of intermediate variables and your "clear" code is wrapped around a lot of repetitions, that only add noise. It just happens that you are m…
Intermediate stream operations like map or filter are always lazy. And .findFirst() is a short-circuiting terminal operation, that does not need to consume all stream elements.
https://docs.oracle.com/en/java/javase/11/docs/api/java.base...