File tree Expand file tree Collapse file tree 3 files changed +5
-5
lines changed Expand file tree Collapse file tree 3 files changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -195,7 +195,7 @@ List<String> list = new ArrayList<>();
195
195
list. add(" 沉默王二" );
196
196
list. add(" 沉默王三" );
197
197
list. add(" 一个文章真特么有趣的程序员" );
198
- for (int i = 0 , n = list. size(); i < n ; i++ ) {
198
+ for (int i = 0 ; i < list. size(); i++ ) {
199
199
String str = list. get(i);
200
200
if (" 沉默王二" . equals(str)) {
201
201
list. remove(str);
Original file line number Diff line number Diff line change 30
30
31
31
Java 集合框架可以分为两条大的支线:
32
32
33
- - Collection,主要由 List、Set、Queue 组成,List 代表有序、可重复的集合,典型代表就是封装了动态数组的 ArrayList 和封装了链表的 LinkedList;Set 代表无序、不可重复的集合,典型代表就是 HashSet 和 TreeSet;Queue 代表队列,典型代表就是双端队列 ArrayDeque,以及优先级队列 PriorityQue 。
33
+ - Collection,主要由 List、Set、Queue 组成,List 代表有序、可重复的集合,典型代表就是封装了动态数组的 ArrayList 和封装了链表的 LinkedList;Set 代表无序、不可重复的集合,典型代表就是 HashSet 和 TreeSet;Queue 代表队列,典型代表就是双端队列 ArrayDeque,以及优先级队列 PriorityQueue 。
34
34
- Map,代表键值对的集合,典型代表就是 HashMap。
35
35
36
36
“接下来,我们再来过一遍。”
Original file line number Diff line number Diff line change @@ -139,9 +139,9 @@ public class Husband {
139
139
140
140
```
141
141
Husband husband = new Husband();
142
- husband.age \ = 30;
143
- husband.name \ = "张三";
144
- husband.sex \ = "男"; //貌似有点儿多余
142
+ husband.age = 30;
143
+ husband.name = "张三";
144
+ husband.sex = "男"; //貌似有点儿多余
145
145
```
146
146
147
147
但是那哪天如果我们需要修改 Husband,例如将 age 修改为 String 类型的呢?你只有一处使用了这个类还好,如果你有几十个甚至上百个这样地方,你是不是要改到崩溃。如果使用了封装,我们完全可以不需要做任何修改,只需要稍微改变下 Husband 类的 setAge()方法即可。
You can’t perform that action at this time.
0 commit comments