2015-11-11 20:20:04 -08:00
|
|
|
// streams/FunctionMap3.java
|
2015-12-15 11:47:04 -08:00
|
|
|
// (c)2016 MindView LLC: see Copyright.txt
|
2015-11-15 15:51:35 -08:00
|
|
|
// We make no guarantees that this code is fit for any purpose.
|
|
|
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
2015-11-11 20:20:04 -08:00
|
|
|
// Producing numeric output streams
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.stream.*;
|
|
|
|
|
|
|
|
class FunctionMap3 {
|
|
|
|
public static void main(String[] args) {
|
|
|
|
Stream.of("5", "7", "9")
|
|
|
|
.mapToInt(Integer::parseInt)
|
2015-11-14 16:18:05 -08:00
|
|
|
.forEach(n -> System.out.format("%d ", n));
|
|
|
|
System.out.println();
|
2015-11-11 20:20:04 -08:00
|
|
|
Stream.of("17", "19", "23")
|
|
|
|
.mapToLong(Long::parseLong)
|
2015-11-14 16:18:05 -08:00
|
|
|
.forEach(n -> System.out.format("%d ", n));
|
|
|
|
System.out.println();
|
2015-11-11 20:20:04 -08:00
|
|
|
Stream.of("17", "1.9", ".23")
|
|
|
|
.mapToDouble(Double::parseDouble)
|
2015-11-14 16:18:05 -08:00
|
|
|
.forEach(n -> System.out.format("%f ", n));
|
2015-11-11 20:20:04 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Output:
|
2015-11-14 16:18:05 -08:00
|
|
|
5 7 9
|
|
|
|
17 19 23
|
|
|
|
17.000000 1.900000 0.230000
|
2015-11-11 20:20:04 -08:00
|
|
|
*/
|