java - create a list from subproperties of another list -
i have 3 classes defined getters , setters follows orm:
class author {   integer id;   string name; }  class bookauthor {   integer id_book;   author author; }  class book {   string title;   list<bookauthor> authors; }   i'd create list of id_author class book. i've found way using streams. i've tried this:
list<integer> result = authors.stream().map(bookauthor::getauthor::getid).collect(collectors.tolist());   but not seem work. can access "id" property in author class?
edit: maybe way be:
list<author> authorlist = authors.stream().map(bookauthor::getauthor).collect(collectors.tolist()); list<integer> result = authorlist.stream().map(author::getid).collect(collectors.tolist());   thank you.
i assume authors variable list (or collection) of bookauthor, not author (that seems based on code).
i think have right idea, dont think can chain :: operators.
so try lambda:
authors.stream().      map(ba -> ba.getauthor().getid()).      collect(collectors.tolist());      
Comments
Post a Comment