You can use the map and collect methods of the Stream class to achieve this.
In Java 8, the map() and flatMap() methods are part of the Stream API, and are used to transform the elements of a stream.