Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

2d Arraylist

 
kalai sundar
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My problem is
for(int i=0;i<10;i++)
{
DNewRow.add(i,NewRow);
}

Here NewRow,DNewRow is Arraylist , so for the i'th index, the NewRow arrayList will be stored,like that for every index of the i'th value NewRow will be added to DNewRow.

now i want to reterive that value, c in 2d array we will retrive as follows
for(int i=0;i<arr[].lenght;i++){
for(int j=0;j<arr2[].lenght;j++){
SOP(New2D[i][j]);
}

How i can reteiver for ArrayList, plz hepl me


kalai
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hint: The opposite to add is the get method. This takes one parameter - the index of the value you want to retrieve. Which value do you want to retrieve? The ith.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know how to get an element from a "1D" ArrayList? If so, you basically do the same thing twice witha "2d" ArrayList. It sounds like you might need some more help with the Collections Framework in general. You should take a look at the Collections Trail from Sun's Java Tutorial. You should also take the time to become intimately familiar with the API documentation for the version of Java you are using.

After reviewing the links I have given above, please come back with more questions if anything is still unclear.

Layne
 
kalai sundar
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to reterive i'th value
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know, I told you that two posts ago

To retrieve the first value: list.get(0)
To retrieve the second value:list.get(1)
To retrieve the third value: list.get(2)
To retrieve the xth value: list.get(x)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic