forked from janbodnar/Java-Advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModifyList.java
More file actions
45 lines (32 loc) · 955 Bytes
/
ModifyList.java
File metadata and controls
45 lines (32 loc) · 955 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
34
35
36
37
38
39
40
41
42
43
44
45
package com.zetcode;
import java.util.ArrayList;
import java.util.List;
public class ModifyList {
public static void main(String[] args) {
List<String> items = new ArrayList<>();
fillList(items);
System.out.println(items);
items.set(3, "watch");
items.add("bowl");
items.remove(0);
items.remove("glass");
System.out.println(items);
items.removeIf(e -> e.charAt(0) == 'p');
System.out.println(items);
items.clear();
if (items.isEmpty()) {
System.out.println("The list is empty");
} else {
System.out.println("The list is not empty");
}
}
private static void fillList(List<String> items) {
items.add("coin");
items.add("pen");
items.add("pencil");
items.add("clock");
items.add("book");
items.add("spectacles");
items.add("glass");
}
}