-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathIntArrayList.java
More file actions
33 lines (28 loc) · 895 Bytes
/
IntArrayList.java
File metadata and controls
33 lines (28 loc) · 895 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
package com.ironhack;
public class IntArrayList implements IntList{
private int[] array = new int[10];
private int size = 0;
int i;
@Override
public void add(int number) {
if ( array.length == size ){
int newArraySize =(array.length /2) * 3; // 50% artirsin
int [] newArray = new int [newArraySize] ;
for (int i=0 ; i<array.length;i++){
newArray[i] = array [i];
}
this.array = newArray;
System.out.println("Array length is now: " + array.length);
}
array[size] = number;
size++; //array-e elave etsin
}
@Override
public void get(int id) {
if (id < 0 || id >= size) {
System.err.println("Error:No element in " + id + "id.");
} else {
System.out.println("Element: " + array[id]);
}
}
}