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

Method main

streams/CollectionToStream.java:9–31  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

7
8public class CollectionToStream {
9 public static void main(String[] args) {
10 List<Bubble> bubbles = Arrays.asList(
11 new Bubble(1), new Bubble(2), new Bubble(3));
12 System.out.println(
13 bubbles.stream()
14 .mapToInt(b -> b.i)
15 .sum());
16
17 Set<String> w = new HashSet<>(Arrays.asList(
18 "It's a wonderful day for pie!".split(" ")));
19 w.stream()
20 .map(x -> x + " ")
21 .forEach(System.out::print);
22 System.out.println();
23
24 Map<String, Double> m = new HashMap<>();
25 m.put("pi", 3.14159);
26 m.put("e", 2.718);
27 m.put("phi", 1.618);
28 m.entrySet().stream()
29 .map(e -> e.getKey() + ": " + e.getValue())
30 .forEach(System.out::println);
31 }
32}
33/* Output:
346

Callers

nothing calls this directly

Calls 7

sumMethod · 0.80
splitMethod · 0.80
streamMethod · 0.45
putMethod · 0.45
entrySetMethod · 0.45
getKeyMethod · 0.45
getValueMethod · 0.45

Tested by

no test coverage detected