So I am trying to do this assignment on ArrayList for the first time and am stuck with a error message that I am not sure how to deal with. So first I build a class called ArrayList: some of the code for that is as follow:-
public class ArrayList
{
ArrayList list = new ArrayList();
public void add(Object a, int index)
{
list.add(null,0);
list.add(a,index);
}
public void insert(Object b, int index)
{
list.add(b,index);
}
public Object remove(int index)
{
Object c = get(index);
list.remove(index);
return c;
}
public Object get(int index)
{
return (list.get(index));
}
public int size()
{
int length = list.size();
return length;
}
}
there is more code to it but i think for my question this much will suffice. So after that I built another class that contains my main driver for testing which is:-
public class DataStructuresDriver
{
public static void main(String[] args)
{
//stackTests();
//queueTests();
arrayListTests();
}
private static void arrayListTests()
{
//todo: make more tests here
ArrayList a = new ArrayList();
a.add('A',2);
a.insert('B', 0);
a.insert('a',0);
a.insert('t',1);
System.out.println(a.toString());
while(a.isEmpty() == false)
{
System.out.println(a.remove(0));
}
}
when i compile the two classes i get no errors but when i run my main code it gives me java.lang.StackOverflowError null, so not sure how to proceed?