Skip to content
Advertisement

Java 8 convert for loop and summing of values to stream/lambda?

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:

JavaScript

I was trying to do something like

JavaScript

… but couldn’t get the summ’ing logic down. could anyone point me in the right direction?

Advertisement

Answer

You need to apply first the matcher then filter on the find

JavaScript

It could more clear for you to see it using lambda function but that’s the same

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement