Skip to content

Tag: java-8

Accumulator Generator test – Java 8

Paul Graham, in his great article Revenge of the Nerds, claimed that languages vary in power. He mentioned a nice exercise – writing an accumulator generator: We want to write a function that generates accumulators– a function that takes a number n, and returns a function that takes another number…

Iterate an Enumeration in Java 8

Is it possible to iterate an Enumeration by using Lambda Expression? What will be the Lambda representation of the following code snippet: I didn’t find any stream within it. Answer In case you don’t like the fact that Collections.list(Enumeration) copies the entire contents into a (temporary) list befo…

Merge lists with stream API

I have the following situation I have to merge all the lists lst from the ListContainer objects from a Map map. Any idea how, using Java 8 stream API? Answer I think flatMap() is what you’re looking for. For example: