File tree Expand file tree Collapse file tree
main/java/cn/byhieg/collectiontutorial/listtutorial
test/java/cn/byhieg/collectiontutorialtest Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package cn .byhieg .collectiontutorial .listtutorial ;
2+
3+ /**
4+ * Created by byhieg on 17/2/7.
5+ * Mail to byhieg@gmail.com
6+ */
7+ public class MyArrayList <E > {
8+
9+
10+ private final static int DEFAULT_CAPACITY = 10 ;
11+ private int size ;
12+
13+ private Object [] elementData ;
14+
15+ //默认的构造方法
16+ public MyArrayList (){
17+ this (DEFAULT_CAPACITY );
18+ }
19+
20+ public MyArrayList (int size ){
21+ if (size < 0 ){
22+ throw new IllegalArgumentException ("默认的大小" + size );
23+ }else {
24+ elementData = new Object [size ];
25+ }
26+ }
27+
28+
29+ }
Original file line number Diff line number Diff line change 22
33import cn .byhieg .collectiontutorial .listtutorial .ArrayListDemo ;
44import junit .framework .TestCase ;
5-
65import java .util .Iterator ;
76
87/**
@@ -17,10 +16,17 @@ public void testList() throws Exception{
1716 for (int i = 0 ;i < 10 ; i ++){
1817 demo .getListA ().add (i );
1918 }
20- Iterator iterator = demo .getListA ().iterator ();
21- while (iterator .hasNext ()) {
22- System .out .println (iterator .next ());
19+ Iterator iteratorA = demo .getListA ().iterator ();
20+ while (iteratorA .hasNext ()) {
21+ System .out .println (iteratorA .next ());
22+ }
23+
24+ demo .setListC (demo .getListA ());
25+ Iterator iteratorC = demo .getListC ().iterator ();
26+ while (iteratorC .hasNext ()) {
27+ System .out .println (iteratorC .next ());
2328 }
29+
2430 }
2531
2632}
You can’t perform that action at this time.
0 commit comments