java - How to get two dimentional array max size if different lengths -
i trying set array size in dynamically. here input values array values are
int[][] dubarr={{2,5,6},{2,5,4,7}}; i want set array size
int[][] size=new int[dubarr.length][dubarray[0].length]; but problem here cant store second array last value
dont [dubarray[1].length] ;
finding maximum length of second dimension , creating new array in single line makes array square, lose information shape. suppose want deep-copy of original array in original shape:
if (dubarr == null) { return null; } final int[][] size = new int[dubarr.length][]; (int = 0; < dubarr.length; i++) { size[i] = dubarr[i].clone(); } return size; this work if dubarr null or empty.
Comments
Post a Comment