Lambdas and streams are not exotic objects to be used in complex algorithms within the reach only of researchers locked away in the labs of a multinational corporation. Even in the life of the everyday developer, they can make life easier; remember: less code and more elegance equal fewer bugs and headaches. Let us look at a few simple cases involving strings:
String string = "abc";
boolean containsAtLeastOneC = string.chars().anyMatch(c -> c == 'b');
System.out.println(containsAtLeastOneC);// prints `true`
boolean allC = string.chars().allMatch(c -> c == 'b');
System.out.println(allC);// prints `false`
boolean noneMatch_a = string.chars().noneMatch(c -> c == 'a');
System.out.println(noneMatch_a);// prints `false`
boolean noneMatch_d = string.chars().noneMatch(c -> c == 'd');
System.out.println(noneMatch_d);// prints `true`
Without the lambdas and character streams, which can be obtained via the new chars() method,
you would probably have cycled over the individual characters in the string, checking them one at a time,
or you would have used a regular expression if possible.
Old-school example:
for (int i = 0; i < string.length(); i++) {
char c = string.charAt(i);
if (c == 'b') System.out.println("Contains one b");
}
