package MyCollections;

public class MyArrayList <v> {
	
	private int size;
	private v[] arr;
	private int index;
	
	MyArrayList(){
		
		size = 10;
		index = 0;
		arr =(v[]) new Object[size];
	}
	
	public void add(v value) {
		if (index >= arr.length)
			erzeuge_neue_array();
		
		arr[index] = value;
		index++;
	}
	
	public void erzeuge_neue_array() {
		
		size *=2;
		v[] neuArray =(v[]) new Object[size];
		for (int i = 0; i < arr.length; i++) 
			neuArray[i] = arr[i];
		
		arr = neuArray;
	}
	
	public void printall() {
		int i = 0;
		while(arr[i] != null) {
			System.out.print(arr[i] + " ");
			i++;
		}
			
	
	}
	
	
	public static void main(String[] args) {
		MyArrayList<Integer> mylist = new MyArrayList<>();
		for (int i = 1; i <= 30; i++)
			mylist.add(i);
		
		mylist.printall();
	}

}
