-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntArrayList.java
More file actions
32 lines (27 loc) · 675 Bytes
/
IntArrayList.java
File metadata and controls
32 lines (27 loc) · 675 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
import java.util.Arrays;
public class IntArrayList implements IntList{
private int[] array;
private int size;
public IntArrayList() {
array = new int[10];
size = 0;
}
@Override
public void add(int number) {
if (size == array.length) {
array = Arrays.copyOf(array, array.length + array.length / 2);
}
array[size++] = number;
}
/* @Override
public int get(int id) {
return 0;
}*/
@Override
public int get(int id) {
if (id < 0 || id >= size) {
throw new IndexOutOfBoundsException("ID out of bounds");
}
return array[id];
}
}