-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathIntArrayList.java
More file actions
48 lines (40 loc) · 990 Bytes
/
IntArrayList.java
File metadata and controls
48 lines (40 loc) · 990 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
39
40
41
42
43
44
45
46
47
48
package com.ironhack;
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){
int newArraySize = array.length + array.length/2;
int[] newArray = new int[newArraySize];
for (int i=0; i<array.length; i++){
newArray[i]=array[i];
}
newArray[array.length+1] = number;
setArray(newArray);
size++;
}
array[size] = number;
size++;
}
@Override
public int get(int id){
return array[id];
}
public int[] getArray() {
return array;
}
public void setArray(int[] array) {
this.array = array;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
}