Java Guild Meeting 5/2018


Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

Micro kata's

Here are a few micro kata's for you to solve, let's get to know some more possibilities of Streams!

If you want to know if your solution is optimal you can take look at the source & solutions.

The kata's are written in old-style Java code. Re-write them into beautiful one-liners using Streams.

alt text

Remember, you can find the documentation on Streams right here.

Flatten this multidimensional collection
Get the oldest person from the collection
Sum all elements of a collection, try to use the reduce operator with identity parameter instead of an IntStream
Get the names of all kids under the age of 18

Not very interesting as an exercise, but check out this example of how to easily generate numerical statistics from an IntStream.

Partition these people into adults and kids, you'll need a special collector for this one
Group these people by nationality, same kind as the previous exercise
Return a comma-separated string of all these people's names


Write a method that returns a comma separated string based on a given list of integers. Each element should be preceded by the letter 'e' if the number is even, and preceded by the letter 'o' if the number is odd. For example, if the input list is (3,44), the output should be 'o3,e44'.

You can write this using only one operator and one collect statement. Go here and click 'Solution' if you want to see the optimal solution.

Return a comma-separated string of all these people's names
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content