This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
My question is how can I access the individual elements of this Arraylist, like GroupName, EventName and the various fields inside the SecurityFunctionVO class which is a value object.
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[1][2] is nothing more than (array[1])[2] - first the value array[1] 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()[2] 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.