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
Post a Comment