java - How do I add a null object to an ArrayList inside an ArrayList -
i trying represent ad hoc network using adjacency matrix structure. this, creating arraylist inside arraylist. when add new vertex graph, create new arraylist (inside super arraylist) , have loop add new null object each arraylist, size of arraylists not increase correctly , can't figure out why. here code: public class matrix { public arraylist<arraylist<edge>> graph; public arraylist<vertex> verticies; public arraylist<edge> edges; public matrix() { graph = new arraylist(); verticies = new arraylist(); edges = new arraylist(); } public matrix(arraylist<vertex> verticies, arraylist<edge> edges) { this.verticies = verticies; this.edges = edges; } public void addvertex(vertex v) { verticies.add(v); graph.add(new arraylist()); for(int i=0; i<graph.size()-1; i++ ) { graph.get(i).add(null); } } any appreciated. the initial size of graph 0 , for loop in addvertex() runs