Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Matrix structure

 
selvas kumars
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,
Is there any data structure(any class) in java to hold matrix data(ie in table form)??
Thanks,
Regards,
silva.
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
what do you mean by matrix data ?
would just an n-dimensional array do the job ?
pascal
 
selvas kumars
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi pascal,
you are right .i want to store n dimension structure..specify me which class i can use for this.
Regards,
silva.
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
this is what you could do to store any kind of objects. you can adapt it to your needs.
Object[][] matrix = new Object[3][4];
this creates an two dimensional array:
[0/0][0/1][0/2][0/3]
[1/0][1/1][1/2][1/3]
[2/0][2/1][2/2][2/3]
iterate through the array:
for (int x = 0; x < matrix.length; x++) {
for (int y = 0; y < matrix[x].length; y++) {
// do something.....maybe print it to system out ??
System.out.println(""+matrix[x][y]);
}
}

hope this helps,
pascal
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic