How to store a 2D array in a regular array? Java -


basically want able store 2d array such this

int [][] preferredmoves = {             {0,0}, {0, arrlength}, {length%2, arrlength},             {0, length%2}, {arrlength, 0}, {0, length%2},              {arrlength, arrlength}, {length%2, length%2},             {arrlength, length%2}, {length%2, 0}     }; 

in single

int [] moves;  

array.

i'm sure possible since i'm storing list..., can't seem find information on anywhere... or maybe not possible?

edit dealing matrices. want store list in single array return array use elsewhere.

so every time call it, have this...

int row = computer.moves()[0];     int col = computer.moves()[1]; 

i need loop through single array, contains 2d array multiple times..

not sure if meant, drop internal { ... } convert one-dimensional array:

int [] moves = {         0, 0, 0, arrlength, length % 2, arrlength,         0, length % 2, arrlength, 0, 0, length % 2,          arrlength, arrlength, length % 2, length % 2,         arrlength, length % 2, length % 2, 0 }; 

and can translate 2d indexes (i, j) 1d index k using formula:

k = * 2 + j; 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -