# Problem in ArrayList

• 02-14-2011, 07:35 PM
justbeller
Problem in ArrayList
I wana use 2 dimensional String in ArrayList lke this

ArrayList<String[][]> list=new ArrayList<String[][]>();
but how can i add 2 String in ArrayList

• 02-14-2011, 07:38 PM
KevinWorkman
You'd have to create a 2 dimensional array of Strings, then add that to the ArrayList.

Recommended reading: Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)
• 02-14-2011, 07:41 PM
justbeller
but i dont know the length of text
• 02-14-2011, 07:54 PM
KevinWorkman
Quote:

Originally Posted by justbeller
but i dont know the length of text

I have no idea what you're asking, as you haven't actually described your problem or your question. Post an SSCCE that demonstrates where you're stuck, describe what you're trying to do, describe any problems you're having, and we'll go from there.
• 02-14-2011, 10:20 PM
j2me64
Quote:

Originally Posted by justbeller
but i dont know the length of text

when you use arrays you should know the length of the elements, otherwise you will never be able to create them.
• 02-15-2011, 08:43 AM
justbeller
if you dont length then specially design ArrayList for it
but I dont how to use 2 dimensional array in ArrayList
• 02-15-2011, 02:01 PM
A 2d array in an arraylist is just a list of lists of lists. Essentially you have created a 3 dimensional array with the first dimension being dynamic. I have no idea what you would do with something like this, but it might be used in this way:
Code:

```//initialize the 2d array ArrayList<String[][]> listOfLists = new ArrayList<String[][]>(); //Do this for every 2d array String[][] array2d = new String[10][10]; array2d[0][0] = "Hi"; array2d[0][1] = "There"; array2d[1][0] = "Hello"; array2d[1][1] = ","; array2d[1][2] = "World!"; //... //Do this for every 2d Array listOfLists.add(array2d);```
Now, again, why would you want this? This might not be the best data structure for you to use - what are you trying to do?
• 02-15-2011, 03:59 PM
justbeller
already done this but im trying to use separate way
• 02-15-2011, 04:19 PM