collections - How can I make streams return lists? (Java) -


this question has answer here:

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

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -