I have 4 string arrays like this:
String[] array1 = new String{"there", "there2", "there3", "there4"};
String[] array2 = new String{"here","here2","here3"};
String[] array3 = new String{"hi","hi2"};
String[] array4 = new String{"blah","blah2","blah3"};
And I want to put these into an array of arrays that would look something like this:
Array myArray = [{"there", "there2", "there3", "there4"},
{"here","here2","here3"},{"hi","hi2"},
{"blah","blah2","blah3"}];
And then would be able to access element in it somewhat like this:
myArray[0][1] would equal "there2"
myArray[1][2] would equal "here3"
Hope that makes sense, how could I go about doing this?
I have tried making an ArrayList like this and then adding them but it doesn't seem to work
ArrayList<String[]> myArrayList = new ArrayList<String[]>();
myArrayList.add(myArray);
It's simple. Check this link for more information about Creating, Initializing, and Accessing an Array.
String[] array1 = new String[]{"there", "there2", "there3", "there4"};
String[] array2 = new String[]{"here", "here2", "here3"};
String[] array3 = new String[]{"hi", "hi2"};
String[] array4 = new String[]{"blah", "blah2", "blah3"};
String[][] allArray = {
array1,
array2,
array3,
array4
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With