tags:

views:

91

answers:

3

Hello In my android application i need to insert an array into an array and access its values. Is there any way that i can get this done.

Please share your valuable suggestions Thanks in advance :)

A: 

You are basically making a list of lists. Create a new list then add that list to the master list. Use generics so you don't have to do a lot of casting.

List<Object> listOfObjects = new ArrayList<Object>();
listOfObjects.add(obj1);
listOfObjects.add(obj2);
List<List<Object>> listOfLists = new ArrayList<List<Object>>();
listOfLists.add(listOfObjects);

// get first object in first list
listOfLists.get(0).get(0);

// add to the first list
listOfLists.get(0).add(0);
Murdock
A: 

Here a example, but for It is for C#

ArrayList MainArray = new ArrayList();

MainArray.Add(new ArrayList());
MainArray.Add(new ArrayList());
MainArray.Add(new ArrayList());

(MainArray[1] as ArrayList).Add("Hello");

Response.Write((MainArray[1] as ArrayList)[0].ToString());
kofucii
A: 

So what' the issue >>>

Give this a try

ArrayList l1 = new ArrayList ();

now suppose you have array objects arr1, arr2 ............ you can add them into arraylist ast

l1.add(arr1); l1.add(arr2);

Now you can access each element in l1 as

for(int i=0; i < l1.size;i++){ obj = l1.get(i);

/// and do what you want to do 

}

success_anil
Thanks anil it worked.
Remmyabhavan