I am here trying to get an element from my two dimensional ArrayList but getting IndexOutOfBoundException error. What am I doing wrong here? Do I need to allocate the space like in a simple Array first? If so, How can I do it in two dimensional array? Below is the code,
import java.util.ArrayList;
public class Test {
private ArrayList<ArrayList<String>> array;
public Test(){
array = new ArrayList<ArrayList<String>>();
array.get(0).set(0, "00");
array.get(0).set(1, "01");
array.get(0).set(2, "02");
array.get(1).set(0, "10");
array.get(1).set(1, "11");
array.get(1).set(2, "12");
array.get(2).set(0, "20");
array.get(2).set(1, "21");
array.get(2).set(2, "22");
}
public String getE(int a, int b){
return array.get(a).get(b);
}
public static void main(String[] args) {
Test object = new Test();
System.out.println(object.getE(0, 0)); // This gives me the error.
}
}