|
1 | 1 | :java-package: src/org/j6toj8/collections |
2 | 2 | :section-java-package: ../../../{java-package} |
3 | 3 |
|
4 | | -=== Fazendo cálculos e coletando resultados de Streams |
| 4 | +=== Perform Calculations and Collecting Streams Results |
5 | 5 |
|
6 | | -.Objetivo |
| 6 | +.Objective |
7 | 7 | -------------------------------------------------- |
8 | 8 | Perform calculations on Java Streams by using count, max, min, average, and sum methods and save results to a collection by using the collect method and Collector class, including the averagingDouble, groupingBy, joining, partitioningBy methods |
9 | | -- |
10 | | -Realizar cálculos em Streams usando os métodos count, max, min, average, e sum e salvar resultados em uma coleção usando o método collect e a classe Collector, incluindo os métodos averagingDouble, groupingBy, joining, partitioningBy |
11 | 9 | -------------------------------------------------- |
12 | 10 |
|
13 | | -. É possível pegar o maior ou menor valor, ou a quantidade de elementos da coleção. |
| 11 | +. You can get the largest or smallest value, or the number of elements in the collection. |
14 | 12 | + |
15 | 13 | [source,java,indent=0] |
16 | 14 | .{java-package}/calculations/Collections_MaxMinCount.java |
17 | 15 | ---- |
18 | 16 | include::{section-java-package}/calculations/Collections_MaxMinCount.java[tag=code] |
19 | 17 | ---- |
20 | 18 | + |
21 | | -.Saída no console |
| 19 | +.console output |
22 | 20 | [source,console] |
23 | 21 | ---- |
24 | 22 | Max: 9 |
25 | 23 | Min: 1 |
26 | 24 | Count: 9 |
27 | 25 | ---- |
28 | 26 |
|
29 | | -. É possível pegar a média dos valores da coleção. |
| 27 | +. You can take the average of the collection values. |
30 | 28 | + |
31 | 29 | [source,java,indent=0] |
32 | 30 | .{java-package}/calculations/Collections_AveragingDouble.java |
33 | 31 | ---- |
34 | 32 | include::{section-java-package}/calculations/Collections_AveragingDouble.java[tag=code] |
35 | 33 | ---- |
36 | 34 | + |
37 | | -.Saída no console |
| 35 | +.console output |
38 | 36 | [source,console] |
39 | 37 | ---- |
40 | 38 | Média: 5.0 |
41 | 39 | ---- |
42 | 40 |
|
43 | | -. É possível agrupar os valores da coleção por uma regra específica. |
| 41 | +. You can group collection values by a specific rule. |
44 | 42 | + |
45 | 43 | [source,java,indent=0] |
46 | 44 | .{java-package}/calculations/Collections_GroupingBy.java |
47 | 45 | ---- |
48 | 46 | include::{section-java-package}/calculations/Collections_GroupingBy.java[tag=code] |
49 | 47 | ---- |
50 | 48 | + |
51 | | -.Saída no console |
| 49 | +.console output |
52 | 50 | [source,console] |
53 | 51 | ---- |
54 | | -Mapa de resto da divisão por 3: {0=[3, 6, 9], 1=[1, 4, 7], 2=[2, 5, 8]} |
| 52 | +Map of rest of division by 3: {0=[3, 6, 9], 1=[1, 4, 7], 2=[2, 5, 8]} |
55 | 53 | ---- |
56 | 54 |
|
57 | | -. É possível concatenar os valores da coleção. |
| 55 | +. You can concatenate the collection values. |
58 | 56 | + |
59 | 57 | [source,java,indent=0] |
60 | 58 | .{java-package}/calculations/Collections_Joining.java |
61 | 59 | ---- |
62 | 60 | include::{section-java-package}/calculations/Collections_Joining.java[tag=code] |
63 | 61 | ---- |
64 | 62 | + |
65 | | -.Saída no console |
| 63 | +.console output |
66 | 64 | [source,console] |
67 | 65 | ---- |
68 | | -Junção dos valores como String: 123456789 |
| 66 | +Join values as String: 123456789 |
69 | 67 | ---- |
70 | 68 |
|
71 | | -. É possível separar os valores da coleção em um mapa com chaves `true` e `false`, de acordo com uma função lambda. |
| 69 | +. You can separate collection values in a map with `true` and `false` keys, according to a lambda function. |
72 | 70 | + |
73 | 71 | [source,java,indent=0] |
74 | 72 | .{java-package}/calculations/Collections_PartitioningBy.java |
75 | 73 | ---- |
76 | 74 | include::{section-java-package}/calculations/Collections_PartitioningBy.java[tag=code] |
77 | 75 | ---- |
78 | 76 | + |
79 | | -.Saída no console |
| 77 | +.console output |
80 | 78 | [source,console] |
81 | 79 | ---- |
82 | | -Mapa de pares e ímpares: {false=[1, 3, 5, 7, 9], true=[2, 4, 6, 8]} |
| 80 | +Even and odd map: {false=[1, 3, 5, 7, 9], true=[2, 4, 6, 8]} |
83 | 81 | ---- |
84 | 82 |
|
| 83 | +.References |
85 | 84 | **** |
86 | 85 |
|
87 | 86 | * Using Streams |
88 | 87 | + |
89 | | -Boyarsky, Jeanne; Selikoff, Scott. OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide (p. 185). Wiley. Edição do Kindle. |
| 88 | +Boyarsky, Jeanne; Selikoff, Scott. OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide (p. 185). Wiley. Kindle Edition. |
90 | 89 |
|
91 | 90 | * https://www.baeldung.com/java-8-streams[The Java 8 Stream API Tutorial.] |
92 | 91 |
|
93 | | -**** |
| 92 | +**** |
0 commit comments