June 2018
Beginner
722 pages
18h 47m
English
The mapToInt(), mapToLong(), mapToDouble() intermediate operations allow us to convert a numeric stream of one type to a numeric stream of another type. For the demonstration code, we convert the list of String values to a numeric stream of different types by mapping each String value to its length:
list.stream().mapToInt(String::length) .forEach(System.out::print); //prints: 335list.stream().mapToLong(String::length) .forEach(System.out::print); //prints: 335list.stream().mapToDouble(String::length) .forEach(d -> System.out.print(d + " ")); //prints: 3.0 3.0 5.0
The elements of the created numeric streams are of a primitive type:
//list.stream().mapToInt(String::length)// .map(Integer::shortValue) ...Read now
Unlock full access