public class MyArrayList<Integer> {
 private final int SIZE=10;
 private int size=0;
 public Integer arr[];
 public MyArrayList(){
	arr=(Integer[])new Object[SIZE];
 }
 public void add(Integer a,int index){
	 if(index>arr.length){
		arr=java.util.Arrays.copyOf(arr, 10+arr.length);
	   size++;
	 }else if(index<0){
		 try {
			throw new Exception();
		} catch (Exception e) {
			
			e.printStackTrace();
		}
	 }else{
		 arr[index]=a;
		 size++;
	 }
 }
 public void add(Integer a){
	 if(size==arr.length){

 arr[size]=a;
 size++;
	 }else{
		 arr[size]=a;
		 size++;
	 }
 }
 public boolean remove(int index){
	 if(index<0||index>size){
		 try {
			throw new Exception();
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	 }else{
		 for(int i=index;i<arr.length-1;i++){
			 arr[i]=arr[i+1];
			 
		 }size--;
		 return true;
	 }
 }
 public void clear(){
	arr=(Integer[])new Object[SIZE];
	 size=0;
 }
 
 public void set(Integer a,int index){
	 if(index>size){
		 try {
			throw new Exception();
		} catch (Exception e) {
			
			e.printStackTrace();
		}
	 }else if(index==size){
		 arr[index]=a;
		 size++;
	 }
	 else if(index<size){
		 arr[index]=a;
	 }
 }
 
 
 public void get(int index){
	 if(index<0||index>size){
		 try {
			throw new Exception();
		} catch (Exception e) {
			
			e.printStackTrace();
		
		}
	 }else{
		 System.out.println(arr[index]);
	 }
 }
 public boolean isEmpty(){
	return size==0;
 }

 public java.util.Iterator<Integer>iterator(){
	 return new ArrayListIterator();
 }
 
public class ArrayListIterator implements java.util.Iterator<Integer>{
	private int current=0;

	@Override
	public boolean hasNext() {
		return size>current;
		
	}

	@Override
	public Integer next() {
		if(!hasNext()){
			return null;
		}else{
		return arr[current++];}
	}

	@Override
	public void remove() {
		// TODO Auto-generated method stub
		MyArrayList.this.remove(--current);
	}
}
 
}