File tree Expand file tree Collapse file tree
src/com/zejian/structures/LinkedList/MyCollection Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .zejian .structures .LinkedList .MyCollection ;
2+
3+ import java .util .ArrayList ;
4+ import java .util .Iterator ;
5+
6+ /**
7+ * Created by zejian on 2016/11/20.
8+ * Blog : http://blog.csdn.net/javazejian [请尊重原创,转载注明出处]
9+ */
10+ public class FailFastTest {
11+
12+ public static void main (String [] args ){
13+ ArrayList <Integer > list =new ArrayList <>();
14+ list .add (10 );
15+ list .add (20 );
16+ list .add (30 );
17+
18+ Iterator iterator =list .iterator ();
19+ while (iterator .hasNext ()){
20+ Integer value = (Integer ) iterator .next ();
21+ if (value ==20 ){
22+ iterator .remove ();//调用iterator的方法移除第2个元素
23+ }else {
24+ System .out .println ("value-->" +value );
25+ }
26+ }
27+ }
28+
29+ }
Original file line number Diff line number Diff line change 1+ package com .zejian .structures .LinkedList .MyCollection ;
2+
3+ import java .util .*;
4+
5+
6+ /**
7+ * Created by zejian on 2016/11/10.
8+ * Blog : http://blog.csdn.net/javazejian [请尊重原创,转载注明出处]
9+ */
10+ public interface IList <T > {
11+ /**
12+ * list大小
13+ * @return
14+ */
15+ int size ();
16+
17+ /**
18+ * 是否为空
19+ * @return
20+ */
21+ boolean isEmpty ();
22+
23+ /**
24+ * 是否包含data
25+ * @param data
26+ * @return
27+ */
28+ boolean contains (T data );
29+
30+
31+ /**
32+ * 清空数据
33+ */
34+ void clear ();
35+
36+ /**
37+ * 根据index获取数据
38+ * @param index
39+ * @return
40+ */
41+ T get (int index );
42+
43+ /**
44+ * 替换数据
45+ * @param index
46+ * @param data
47+ * @return
48+ */
49+ T set (int index , T data );
50+
51+ /**
52+ * 尾部添加数据
53+ * @param data
54+ * @return
55+ */
56+ boolean add (T data );
57+
58+ /**
59+ * 根据index添加数据
60+ * @param index
61+ * @param data
62+ */
63+ void add (int index , T data );
64+
65+ /**
66+ * 移除数据
67+ * @param data
68+ * @return
69+ */
70+ boolean remove (T data );
71+
72+ /**
73+ * 根据index删除数据
74+ * @param index
75+ * @return
76+ */
77+ T remove (int index );
78+
79+ /**
80+ * 根据data获取下标
81+ * @param data
82+ * @return
83+ */
84+ int indexOf (T data );
85+
86+ /**
87+ * 根据data获取最后一个下标
88+ * @param data
89+ * @return
90+ */
91+ int lastIndexOf (T data );
92+
93+
94+
95+
96+ }
You can’t perform that action at this time.
0 commit comments