This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
Smita, A 2D ArrayList isn't a built-in concept in Java like a 2D array is. A 2D ArrayList is really just an ArrayList that happens to contain other ArrayLists. As such, keep this in mind when accessing.
This is what you really have in your example:
Consider using a "real" object to store your values. Or a map if you have name/object pairs. Storing different types of objects in an ArrayList is confusing and hard to maintain. Java 5 introduces generics where you can say what type of ArrayList you have. In your case, you don't really have a type. You have a "bag" of objects that you happen to be storing in an ArrayList.
Originally posted by Jeanne Boyarsky: A 2D ArrayList isn't a built-in concept in Java like a 2D array is. A 2D ArrayList is really just an ArrayList that happens to contain other ArrayLists. As such, keep this in mind when accessing.
Technically, a 2D array isn't a built-in concept either - it's just an array of arrays.
String is basically (String), so an array or arrays of Strings. Even accessing it, lets say array is nothing more than (array) - first the value array is retrieved, which is an array which then has its third element accessed. You can do the same thing with arrays retrieved through methods: "string".toCharArray() is perfectly valid, and returns 'r'.
The only real difference is that there is a shortcut for creating. Whereas new ArrayList<ArrayList<String>> only creates the outer ArrayList, new String[x][y] also creates all inner arrays.