1

What would be the easiest way to implement a matrix of 'set' size m * n in Java? The matrix structure wouldn't need to handle any complex matrix operations such as matrix multiplications or anything, just to hold data - the only thing I would use it for is to access the data at M(i, j), change the data at M(i, j) and set the data at M(i, j) for values 0 <= i < m, 0 <= j < n.

Would the most straight forward approach to this problem be to fill an m-size array with n-size arrays or what is the recommended approach to this? Or is there some better data structure for this altogether?

Nyfiken Gul
  • 654
  • 4
  • 20

4 Answers4

2

Doing this in a performant way that covers all edge-cases will be difficult if you do not already know how to make a basic implementation.

I would suggest using an existing library for this.

For example, take a look at toxiclibs.

sdgfsdh
  • 33,689
  • 26
  • 132
  • 245
1

If you just need a 2-dimensional array with a size of 5*10:

int[][] multi = new int[5][10];
Thomas
  • 8,357
  • 15
  • 45
  • 81
1

I would recommend to use a 2D Array or a library.

For more info you can check https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html

1

If you are looking for matrix calculations on complex numbers (math) you may find a library here.