-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTheList.java
33 lines (24 loc) · 905 Bytes
/
TheList.java
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
import java.util.ArrayList;
import java.util.List;
public class TheList {
public static void main(String[] args) {
List<String> singers = List.of("Ariana", "Dua Lipa", "Katy Perry"); // immutable list
System.out.println(singers);
List<String> nbaPlayers = new ArrayList<>();
nbaPlayers.add("Jordan");
nbaPlayers.add("Kobe");
nbaPlayers.add("James");
System.out.println(nbaPlayers.contains("Stephen"));
System.out.println(nbaPlayers.contains("Kobe"));
System.out.println(nbaPlayers);
for (int i = 0; i < nbaPlayers.size(); i++) {
System.out.println(nbaPlayers.get(i));
}
nbaPlayers.remove("Jordan");
nbaPlayers.remove("Dick");
for (String player : nbaPlayers) {
System.out.println(player);
}
nbaPlayers.forEach(System.out::println);
}
}