I have some String inputs that I am looping over that I am trying to convert to java 8 stream/lambdas but was having some issues. My boilerplate code looks like this:
public static int count(List<String> list) {
String regex = "someRegexPatternHere"
Pattern p = Pattern.compile(regex);
int sum = 0;
for (String val: list) {
Matcher m = p.matcher(val);
if (m.find()) {
// summing logic here
}
}
return sum;
}
I was trying to do something like
list.stream()
.filter(i -> p.matcher(i).find())
.map(..............)
...
... but couldn't get the summ'ing logic down. could anyone point me in the right direction?