MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / main

Method main

arrays/StreamFromArray.java:9–38  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

7
8public class StreamFromArray {
9 public static void main(String[] args) {
10 String[] s = new Rand.String().array(10);
11 Arrays.stream(s)
12 .skip(3)
13 .limit(5)
14 .map(ss -> ss + "!")
15 .forEach(System.out::println);
16
17 int[] ia = new Rand.Pint().array(10);
18 Arrays.stream(ia)
19 .skip(3)
20 .limit(5)
21 .map(i -> i * 10)
22 .forEach(System.out::println);
23
24 Arrays.stream(new long[10]);
25 Arrays.stream(new double[10]);
26
27 // Only int, long and double work:
28 //- Arrays.stream(new boolean[10]);
29 //- Arrays.stream(new byte[10]);
30 //- Arrays.stream(new char[10]);
31 //- Arrays.stream(new short[10]);
32 //- Arrays.stream(new float[10]);
33
34 // For the other types you must use wrapped arrays:
35 float[] fa = new Rand.Pfloat().array(10);
36 Arrays.stream(ConvertTo.boxed(fa));
37 Arrays.stream(new Rand.Float().array(10));
38 }
39}
40/* Output:
41eloztdv!

Callers

nothing calls this directly

Calls 3

boxedMethod · 0.95
arrayMethod · 0.45
streamMethod · 0.45

Tested by

no test coverage detected