# Thread: Problem in ArrayList

1. Member
Join Date
Dec 2010
Posts
57
Rep Power
0

## 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

2. 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)

3. Member
Join Date
Dec 2010
Posts
57
Rep Power
0
but i dont know the length of text

4. 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.

5. 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.

6. Member
Join Date
Dec 2010
Posts
57
Rep Power
0
if you dont length then specially design ArrayList for it
but I dont how to use 2 dimensional array in ArrayList

7. 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:
Java 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
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?

8. Member
Join Date
Dec 2010
Posts
57
Rep Power
0
already done this but im trying to use separate way

9. ... im trying to use separate way
Ok in that case (but only for 'separate way') you need to input all the stuff several times, but only when the smallest is smaller than the largest and only on weekdays.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•