They are not doing the same thing - the Predicate uses find
rather than matches
. The equivalent 'old code' way would be:
for (String lang : progLangs) {
if (p.matcher(lang).find()) {
System.out.println(lang);
}
}
In this case I would use my own predicate:
progLangs.stream()
.filter(s -> p.matcher(s).matches())
.forEach(System.out::println);
The documentation does seem misleading though.