Hey everyone! If I have a matrix as follows:

int[][] mat = new int[5][3];

Does that mean that the row size is 5 and the column size is 3 or vice-versa? I am really confused about whether the order is [row][col] or whether it is [x][y] in relation to the x-y plane, which would be [col][row].

Can someone please explain?

Recommended Answers

All 3 Replies

Doesn't really matter. You can refer to it either way you want, just make sure that you do it the same everywhere in the program, and if the structure is to become "public", make sure that the "direction" is documented.

But is there a standard way it's usually done?

I would assume x,y (i.e. col, row) since that is what x, y is, and how they are normally referenced. But is there some sort of standard, haven't got a clue, as it doesn't matter anyway.

If you are uncertain of a specific third-party library you're using, then use that library with a known set of data, and find out which is which.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.