forked from janbodnar/Java-Advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListInit.java
More file actions
33 lines (26 loc) · 815 Bytes
/
ListInit.java
File metadata and controls
33 lines (26 loc) · 815 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 com.zetcode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ListInit {
public static void main(String[] args) {
var words = new ArrayList<String>();
words.add("rock");
words.add("forest");
words.add("wood");
words.add("river");
System.out.println(words);
var drinks = new ArrayList<String>() {{
add("beer");
add("lemonade");
add("juice");
add("coffee");
add("tea");
}};
System.out.println(drinks);
var colours = Arrays.asList("blue", "red", "green", "yellow");
System.out.println(colours);
var seasons = List.of("spring", "summer", "autumn", "winter");
System.out.println(seasons);
}
}