forked from miciek/grokkingfp-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathch03_ListVsString.java
More file actions
38 lines (25 loc) · 1022 Bytes
/
Copy pathch03_ListVsString.java
File metadata and controls
38 lines (25 loc) · 1022 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
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ch03_ListVsString {
public static void main(String[] args) {
List<String> listA = new ArrayList<>();
listA.add("A");
List<String> listB = new ArrayList<>();
listB.add("B");
listA.addAll(listB);
assert(listA.equals(Arrays.asList("A", "B")) && listB.equals(Arrays.asList("B")));
String stringA = "A";
String stringB = "B";
String stringAB = stringA.concat(stringB);
assert(stringA.equals("A") && stringB.equals("B") && stringAB.equals("AB"));
List<String> listXY = new ArrayList<>();
listXY.add("X");
listXY.add("Y");
List<String> listY = listXY.subList(1, 2);
assert(listXY.equals(Arrays.asList("X", "Y")) && listY.equals(Arrays.asList("Y")));
String stringXY = "XY";
String stringY = stringXY.substring(1, 2);
assert(stringXY.equals("XY") && stringY.equals("Y"));
}
}