-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(collections): 🎸 collection improvements, translated
Refers: #10
- Loading branch information
1 parent
da1b2c7
commit 731a4ad
Showing
5 changed files
with
32 additions
and
33 deletions.
There are no files selected for viewing
45 changes: 22 additions & 23 deletions
45
book/08-java-collections/sections/05-collection-improvements.asc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,82 @@ | ||
:java-package: src/org/j6toj8/collections | ||
:section-java-package: ../../../{java-package} | ||
|
||
=== Melhorias de Java 8 em Coleções | ||
=== Java 8 collection improvements | ||
|
||
.Objetivo | ||
.Objective | ||
-------------------------------------------------- | ||
Develop code that uses Java SE 8 collection improvements, including the Collection.removeIf(), List.replaceAll(), Map.computeIfAbsent(), and Map.computeIfPresent() methods | ||
- | ||
Desenvolver código que use as melhorias em coleções do Java SE 8, incluindo os métodos Collection.removeIf(), List.replaceAll(), Map.computeIfAbsent(), e Map.computeIfPresent() | ||
-------------------------------------------------- | ||
|
||
O Java 8 trouxe vários métodos em Collections que utilizam como argumento uma função lambda, facilitando algumas operações. Serão apresentados exemplos dos 4 métodos relacionados a esse objetivo. | ||
Java 8 has introduced several methods in Collections that use a lambda function as argument, making some operations easier. Examples of the 4 methods related to this objective will be presented. | ||
|
||
. É possível remover um item de uma coleção condicionalmente com uma função lambda. | ||
. You can conditionally remove an item from a collection with a lambda function. | ||
+ | ||
[source,java,indent=0] | ||
.{java-package}/improvements/Collections_RemoveIf.java | ||
---- | ||
include::{section-java-package}/improvements/Collections_RemoveIf.java[tag=code] | ||
---- | ||
+ | ||
.Saída no console | ||
.console output | ||
[source,console] | ||
---- | ||
Lista antes do removeIf: [1, 2, 3, 4, 5, 6, 7, 8, 9] | ||
Lista depois do removeIf: [1, 3, 5, 7, 9] | ||
List before removeIf: [1, 2, 3, 4, 5, 6, 7, 8, 9] | ||
List after removeIf: [1, 3, 5, 7, 9] | ||
---- | ||
|
||
. É possível modificar todos os elementos da coleção de acordo com uma operação lambda. | ||
. You can modify all elements of the collection according to a lambda operation. | ||
+ | ||
[source,java,indent=0] | ||
.{java-package}/improvements/Collections_ReplaceAll.java | ||
---- | ||
include::{section-java-package}/improvements/Collections_ReplaceAll.java[tag=code] | ||
---- | ||
+ | ||
.Saída no console | ||
.console output | ||
[source,console] | ||
---- | ||
Lista antes do replaceAll: [1, 2, 3, 4, 5, 6, 7, 8, 9] | ||
Lista depois do replaceAll: [2, 4, 6, 8, 10, 12, 14, 16, 18] | ||
List before replaceAll: [1, 2, 3, 4, 5, 6, 7, 8, 9] | ||
List after replaceAll: [2, 4, 6, 8, 10, 12, 14, 16, 18] | ||
---- | ||
|
||
. É possível colocar valores em um `Map` a partir de uma função lambda, apenas se a chave *não* estiver presente no `Map`. | ||
. You can put values in a `Map` from a lambda function only if the *key* is not present in `Map`. | ||
+ | ||
[source,java,indent=0] | ||
.{java-package}/improvements/Collections_ComputeIfAbsent.java | ||
---- | ||
include::{section-java-package}/improvements/Collections_ComputeIfAbsent.java[tag=code] | ||
---- | ||
+ | ||
.Saída no console | ||
.console output | ||
[source,console] | ||
---- | ||
Map antes do computeIfAbsent: {A=65, B=66} | ||
Map depois do computeIfAbsent: {A=65, B=66, C=67} | ||
Map before computeIfAbsent: {A=65, B=66} | ||
Map after computeIfAbsent: {A=65, B=66, C=67} | ||
---- | ||
|
||
. É possível alterar valores em um `Map` a partir de uma função lambda, apenas se a chave estiver presente no `Map`. | ||
. You can change values in a `Map` from a lambda function only if the key is present in `Map`. | ||
+ | ||
[source,java,indent=0] | ||
.{java-package}/improvements/Collections_ComputeIfPresent.java | ||
---- | ||
include::{section-java-package}/improvements/Collections_ComputeIfPresent.java[tag=code] | ||
---- | ||
+ | ||
.Saída no console | ||
.console output | ||
[source,console] | ||
---- | ||
Map antes do computeIfPresent: {A=65, B=66} | ||
Map depois do computeIfPresent: {A=4225, B=4356} | ||
Map before computeIfPresent: {A=65, B=66} | ||
Map after computeIfPresent: {A=4225, B=4356} | ||
---- | ||
|
||
.References | ||
**** | ||
* Using Streams | ||
+ | ||
Boyarsky, Jeanne; Selikoff, Scott. OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide (p. 185). Wiley. Edição do Kindle. | ||
Boyarsky, Jeanne; Selikoff, Scott. OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide (p. 185). Wiley. Kindle Edition. | ||
* https://www.baeldung.com/java-8-streams[The Java 8 Stream API Tutorial.] | ||
**** | ||
**** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters