java - Lambda + stream to fetch List<A> to A Single List -


i have class

class testa {             private list<a> lista;        //getters , setters } 

and class

class a{        int id; } 

now if want collect list below code

list<testa> somelist ; //containing testa list<a> completelist = new linkedlist<a>(); for(testa test:somelist) {   if(test.getlista() != null) {     completelist.addall(lista);   } } 

how can completelist using lambda + stream . in advance.

it should this...

  somelist.stream()      .map(testa::getlista)      .filter(testa -> testa != null && !testa.isempty())      .flatmap(list::stream)      .collect(collectors.tolist()); 

Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -