java - Create n amount of arrays -
i know how, if possible, create n amount of arrays of same size. appreciated. example: want create 10 arrays same amount of elements without having create them 1 one: int[] = new int[]
. hope more clear now.
one of questions in 1 of comments +- "how sort array row row / column column". figured out - maybe may find useful.
int[] sortarr = new int[5]; //create array transfer data row new array (int i=0; i<n; i++){ (int j=0; j<5; j++){ sortarr[j] = hands[i][j]; //transfer data 2d array's row sortarr } arrays.sort(sortarr); //sort row's data (int x=0; x<5; x++){ hands[i][x] = sortarr[x]; //transfer data 2d array } }
maybe it's pretty obvious, hope out there.
you need create 2d array.
int n; int size; int[][] arr = new int[size][n];
you can fill array nested for
loop;
for(int =0;i < arr.length; i++) { for(int j = 0; < arr[i].length; j++) { arr[i][j] = somevalue; } }
or populate arrays so:
int[][] arr2 = new int[n][]; for(int = 0; < n; i++){ arr2[i] = new int[size]; }
you can think of 2d array array of arrays, example:
private card[][] allplayerhands; public card[] gethand(int playernumber) { return allplayerhands[playernumber]; }
here stack overflow question 2d arrays:
Comments
Post a Comment