Skip to content
Advertisement

extract list inside a list as a single list

I’ve a two POJOs, Sample code below

JavaScript

Controller class

JavaScript

This returns me a list of the list:

JavaScript

but what I want is a single list like

JavaScript

How can I do that with Java 8 streams?

I’ve tried flatMap also, but that doesn’t go well with the Object datatype of entries.

Advertisement

Answer

Consider a List<String> as a field entries in the A class.

As @Eugene mentioned in the comments,

If it’s a single String make it a List of a single element; if it’s a list of multiple strings make it as such.

Working with a collection of a single type can simplify the process:

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