mapToInt() mapToLong() and mapToDouble() example



import java.util.Arrays;
import java.util.List;
import java.util.OptionalDouble;

public class MapToIntLongDoubleFlight {
public static void main(String[] args) {
List<Integer> numbers = Arrays.asList(1,2,3,4,5,6);
int total = numbers
.stream()
.mapToInt(num->num)
.sum();
System.out.println("Total: "+total);

OptionalInt min = numbers
.stream()
.mapToInt(num->num)
.min();
System.out.println("Smallest Value: "+min.getAsInt());

OptionalInt max = numbers
.stream()
.mapToInt(num->num)
.max();
System.out.println("Largest Value: "+max.getAsInt());

OptionalDouble average = 
numbers
.stream()
.mapToDouble(num->num)
.average();
System.out.println("Average: "+average.getAsDouble());

long totalLong = numbers
.stream()
.mapToLong(num->num*10000)
.sum();
System.out.println("Total Long: "+totalLong);
}
}
Output:
Total: 21
Smallest Value: 1
Largest Value: 6
Average: 3.5
Total Long: 210000

Explanation:
mapToInt method fetch all the number from the list (represented as an Integer) and returns an IntStream as the result (instead of a Stream<Integer>). 

You can then call the sum method available in the IntStream interface to calculate the sum of amounts.
Same way you can use mapToDouble and mapToLong