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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
对动态数组ArrayList部分自带功能进行了实验理解

import java.util.ArrayList;
import java.util.Arrays;

public class Demo1 {
public static void main(String[] args) {
ArrayList<Number> arr1 = new ArrayList<Number>();//定义一个动态数组arr1
ArrayList<Number> arr2 = new ArrayList<Number>();//定义一个动态数组arr2
arr1.add(1);arr1.add(2);arr1.add(3);arr1.add(4);arr1.add(5);
arr1.add(6);arr1.add(7);arr1.add(8);arr1.add(9);arr1.add(10);
arr2.add(10);arr2.add(9);arr2.add(8);arr2.add(7);arr2.add(6);
arr2.add(5);arr2.add(4);arr2.add(3);arr2.add(2);arr2.add(1);
System.out.println(arr1);
System.out.println(arr2);

运行结果

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
int a1 = arr1.size();//获取动态数组arr1的长度
System.out.println(a1);

boolean a2 = arr1.isEmpty();//检验动态数组arr1是否为空
System.out.println(a2);

int a3 = arr1.indexOf(3);//获取元素数字3在动态数组arr1中的位置
System.out.println(a3);
运行结果

10
false
2
boolean a4 = arr1.contains(3);//检验数字元素3是否存在与动态数组arr1中,
boolean a5= arr1.contains(100);//检验数字元素3是否存在与动态数组arr1中
System.out.println(a4);
System.out.println(a5);

arr1.add(3);
System.out.println(arr1);
int a6 = arr1.lastIndexOf(3);//获取动态数组中最后一个数字3所在的位置
System.out.println(a6);

ArrayList<Number> arr4 = (ArrayList<Number>) arr1.clone();//将动态数组arr1中所有的元素复制到动态数组arr4中
System.out.println(arr4);
运行结果

true
false
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 3]
10
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 3]


Object[] arr3 = arr1.toArray();
System.out.println(Arrays.toString(arr3));//将动态数组arr1中的所有元素移到数组arr3(注意输出方式!!数组应用(toString输出)

int a7 = (int) arr1.get(3);//输出动态数组arr1中第三位元素的值
System.out.println(a7);

arr1.set(10, 11);//将动态数组arr1中的第10位元素数值改成11;
System.out.println(arr1);
运行结果

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 3]
4
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
arr1.add(2, 2.5);//在动态数组的第二位怎加元素数值为2.5
System.out.println(arr1);

arr1.remove(2);//移去动态数组arr1中的第2个节点
System.out.println(arr1);

System.out.println(arr1);
arr1.addAll(2, arr2);//将动态数组arr2中所有的节点元素插入入到动态数组arr1中的第二个位置
System.out.println(arr2);
System.out.println(arr1);
运行结果

[1, 2, 2.5, 3, 4, 5, 6, 7, 8, 9, 10, 11]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
[1, 2, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11]
arr2.clear();//清空第二个数组
System.out.println(arr2);

System.out.println(arr4);
System.out.println(arr1);
arr1.removeAll(arr4);//将动态数组arr1中所有和动态数组arr4中相同的的节点元素去除
System.out.println(arr1);
System.out.println(arr4);

arr1.addAll(0,arr4);
System.out.println(arr1);
arr1.retainAll(arr4);//将动态数组arr1中所有动态数组arr4中没有的的节点元素去除
System.out.println(arr1);

// arr1.listIterator();
// arr1.iterator();
// System.out.println(arr1);
// System.out.println(arr1);//还需继续学习
运行结果



[]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 3]
[1, 2, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11]
[11]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 3]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 3, 11]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 3]
有关文件输出流输入流的只是还没有学习到,没有做出解释xxxxxxxxxx [1, 2, 100, 4, 5, 6, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 7, 8, 9, 11, 12][1, 100, 4, 5, 6, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 7, 8, 9, 11, 12][1, 100, 4, 5, 6, 10, 9, 8, 7, 6, 5, 4, 3, 1, 7, 8, 9, 11, 12]