- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayList.java
More file actions
Latest commit
38 lines (35 loc) · 680 Bytes
/
Copy pathArrayList.java
File metadata and controls
38 lines (35 loc) · 680 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
classArrayList<T>{
Object[] elements;
intMAX_SIZE,size;
publicArrayList(){
elements = newObject[256];
MAX_SIZE = 256;
size = 0;
}
publicArrayList(intMAX_SIZE){
elements = newObject[MAX_SIZE];
this.MAX_SIZE = MAX_SIZE;
size = 0;
}
publicvoidadd(Tt){
if (MAX_SIZE == size){ //COPY TO
Object[] array = newObject[2*MAX_SIZE];
for (inti = 0;i<MAX_SIZE; i++){
array[i]=elements[i];
}
MAX_SIZE*=2;
elements=array;
}
elements[size++]=(Object)t;
}
@SuppressWarnings("unchecked")
publicTget(intindex){
return (T)elements[index];
}
publicintsize(){
returnsize;
}
publicObject[] toArray(){
returnelements;
}
}