This is my first class MyArrayList with the method addToEnd that I am trying to run.
public class MyArrayList <E extends Comparable<E>>implements List<E> {
private E[] data;
private int size = 0;
private void reallocate(){
size = 2 * size;
data = Arrays.copyOf(data, size);
}
public boolean addToEnd(E e) {
if (size == data.length){
reallocate();
}
data[size++] = e;
System.out.println();
return true;
}
My second class, ArraySorterTester, is where I am trying to call my addToEnd method, but for some reason it won't work and I keep getting an error.
public class ArraySorterTester {
public static void main(String [] args){
Integer[] test = new Integer[] {1, 2, 4, 6, 8 };
MyArrayList<Integer> inserter = new MyArrayList<Integer>();
boolean sorted = true;
inserter.addToEnd(10);
for (int k = 0; k < test.length; k++) {
System.out.print(test[k] + " ");
}
}