View Single Post
  #1 (permalink)  
Old 07-03-2008, 10:09 AM
coolnfunky_raj coolnfunky_raj is offline
Member
 
Join Date: Jul 2008
Posts: 6
coolnfunky_raj is on a distinguished road
ArrayList of ArrayLists
Hi all

I am new to Java. I am working with ArrayLists and have a couple of questions in that. So here goes..

#1. I have an ArrayList and I keep adding Strings to it. Upon a certain condition, I add this ArrayList to an ArrayList of ArrayLists like this

Code:
class Test { ArrayList<String> arr = new ArrayList<String>(); ArrayList<ArrayList> arrOfArr = new ArrayList<ArrayList>(); public void startElement (String tagName) { arr.add(tagName); } public void endElement () { arrOfArr.add(arr); } public void removeLastElement () { arr.remove(arr.size() -1); } public static void main(String args[]) { Test test = new Test(); test.startElement("ABC"); test.startElement("DEF"); test.endElement(); test.removeLastElement(); test.removeLastElement(); } }
In this code, when removeLastElement() is executed, the elements in arr as well as arrOfArr are removed. Is there a way to remove elements from arr but leave arrOfArr intact?

#2. In the above code, is there a way to convert arrOfArr to a String[][] without iterating through arrOfArr element by element?
Reply With Quote
Sponsored Links