Reputation:
I have a 2D array like ...
ArrayList<ArrayList<MParsingClass>> 2d_arraylist = new ArrayList<ArrayList<MParsingClass>>();
I want to get all the Value of the internal Object class like the value of position ...
2d_arraylist [0][1] and gradually so on.....
Any Help Please ??
Upvotes: 0
Views: 1193
Reputation: 16398
This should work:
for(i=0; i<2d_arraylist.size(); i++) {
ArrayList<MParsingClass> temp = 2d_arraylist.get(i);
for(j=0; j<temp.size(); j++) {
MParsingClass obj = temp.get(j);
//To-Do .....
}
}
Upvotes: 0
Reputation: 61520
That would work if you were dealing with nested arrays, but you are dealing with nested ArrayList
s you have to use ArrayList
class methods to access its data, namely the get()
method.
You need to use:
2d_arraylist.get(0).get(1);
get(0)
gets the first row from your array of arrays (an ArrayList)
get(1)
gets the second column from the row you have selected (an MParsingClass)
Upvotes: 2
Reputation: 2757
You Have to make a 2 for loop like this ...
for(int i=o ; i< size of 2d array ;i++)
// here you have to make another ArrayList which will get the positon of the "i th" //array of your 2D array..
ArrayList<MParsingClass> new_array_list = 2d_arraylist .get(position);
for(int j=o ; i<size of new_array_list ;i++)
new_array_list.get(your get value)
{
}
Upvotes: 0