forked from janbodnar/Java-Advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubList.java
More file actions
33 lines (23 loc) · 756 Bytes
/
SubList.java
File metadata and controls
33 lines (23 loc) · 756 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.List;
// The subList() method returns a view of the portion of this list
// between the specified fromIndex, inclusive, and toIndex, exclusive.
public class SubList {
public static void main(String[] args) {
List<String> items = new ArrayList<>();
items.add("coin");
items.add("pen");
items.add("cup");
items.add("notebook");
items.add("glass");
items.add("chair");
items.add("ball");
items.add("bowl");
List<String> items2 = items.subList(2, 5);
System.out.println(items2);
items2.set(0, "bottle");
System.out.println(items2);
System.out.println(items);
}
}