How to map integers to doubles using Java stream

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class HelloWorld{

     public static void main(String []args){
        List numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
        List doubles = numbers.stream().mapToDouble(Integer::doubleValue).boxed().collect(Collectors.toList());
        List doubleSquares = numbers.stream().mapToDouble(i->i.doubleValue() * 2).boxed().collect(Collectors.toList());
        System.out.println(doubles);
        System.out.println(doubleSquares);
     }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s