Skip to content
Advertisement

How can I use java streams to retrieve the value of x names?

I can use the below snippet to retrieve the name if there is 1 entry in the list by retrieving element 0 in the list, however, each NameResponse can have several names (e.g. a first name, a middle name and a surname). How can I retrieve x names associated with one customer? There could be 20 names for argument’s sake. I would like to implement using a stream since I am using Java 8, but I am unsure how to implement this. Any suggestions?

JavaScript

Customer class:

JavaScript

NameResponse class:

JavaScript

Advertisement

Answer

Something like below assuming you have the appropriate getters:

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