Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ArrayList

 
kalai sundar
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int[][] a = new int[][], array size u just conside some value.
Here bno, Row,Tier are 2D Arrays
for(int i=0;i<bno.lenght();i++){
for(int j=0;j<Row[i].lenght;j++){
for(int k=0;k<Tier[i].lenght;k++)
a[i][j] = Row[i][j].concat(Tier[i][k]

}

}
}

if i want to do the same thing in array list, how i can i do? For example if bno,Row,Tier are 2D Arraylist, how i can do the above mentioned operation, plz hepl me with example
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just create a List of List objects. For example, to have a List containing 10 Lists inside of it, do this:




So then, if I had an Integer myNumber and I wanted to insert it into the 4th element of the 7th List inside of outer, I'd do this:



But be careful not to generate an exception by adding something beyond the bounds of the list. You can get around this by using the ArrayList constructor that takes an initialCapacity, or more likely, you'll simply be calling the add() method each time to add onto the end of the List rather than explicitly setting a value at a particular point in the List.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic