collections - How can I make streams return lists? (Java) -
this question has answer here:
- collection stream new collection 3 answers
i have following list:
observablelist<string> books;
i know if want have sorted list can write
public observablelist<string> getbooks() { return books; } now, question may pretty nonsensical, but... there way achieve same result above streams? like
books .stream() .sorted(); but having stream return me sorted observablelist?
i'm starting learn streams , don't know yet, wondering if possible.
side note: books wrong naming convention variable; use books.
this indeed possible, using collectors. or collectors. assuming observablelist collection of sort, can following:
observablelist<string> hereyougo = books.stream() .sorted() .collect(collectors.tocollection(observablelist::new)); where observablelist::new supplier of empty observablelist collector. change if that's not how class works.
Comments
Post a Comment