Java Streams CheatSheet

devv
594 views
undefined

Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

Streams

Effectively final variable.

// {...}
//Incorrect
for (int i = 0; i < 10; i++) {
new Thread(() -> {
System.out.println("i = " + i); // Does not compile!
}).start();
}
// {...}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// {...}
for (int i = 0; i < 10; i++) {
int j = i; //effectively final
new Thread(() -> System.out.println("i = " + j)).start();
}
// {...}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// {...}
//Incorrect
for (int i = 0; i < 10; i++) {
int j = i;
new Thread(() -> System.out.println("i = " + j)).start();
j++;
}
// {...}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content