forked from PacktPublishing/Java-Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
33 lines (25 loc) · 880 Bytes
/
Copy pathMain.java
File metadata and controls
33 lines (25 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package modern.challenge;
import java.util.List;
public class Main {
public static void main(String[] args) {
// explicit type
System.out.println("Explicit type:");
for (int i = 0; i < 5; i++) {
System.out.print(i + " ");
}
// using var
System.out.println("\n\nLVTI:");
for (var i = 0; i < 5; i++) { // 'i' is inferred of type int
System.out.print(i + " ");
}
List<Player> players = List.of(new Player(), new Player(), new Player());
System.out.println("\n\nExplicit type:");
for (Player player : players) {
System.out.print(player + " ");
}
System.out.println("\n\nLVTI:");
for (var player : players) { // 'player' is inferred of type Player
System.out.print(player + " ");
}
}
}