ArrayList example: Storing the matrix: [1 2 3 4 5 6 7 8 9] ArrayList foo = new ArrayList(); foo.add(object of type type) ; ArrayList > matrix = new ArrayList >(); System.out.println(matrix.size()); // print 0 /*matrix.add(null); // size is 1 matrix.get(0).size() ; // null pointerexception */ matrix.add(new ArrayList()); matrix.add(new ArrayList()); matrix.add(new ArrayList()); matrix.get(0).add(new Integer(1)); matrix.get(0).add(new Integer(2)); matrix.get(0).add(new Integer(3)); matrix.get(1).add(new Integer(4)); matrix.get(1).add(new Integer(5)); matrix.get(1).add(new Integer(6)); ArrayList temp = matrix.get(2); temp.add(new Integer(7)); temp = new ArrayList(); temp.add(new Integer(8)); Sum an ArrayList using recursion: public static int sum(ArrayList array){ if (array.size() == 0) { return 0; } ArrayList arrayCopy = new ArrayList(); arrayCopy.addAll(array); arrayCopy.remove(0); return array.get(0).intValue() + sum(arrayCopy); } public static int sum(ArrayList array){ return sumHelper(array, 0); } private static int sumHelper(ArrayList array, int start) { if ( start == array.size()) { return 0; } return array.get(start).intValue() + sum(array, start+1); }