Multidimensional Arrays lengths in Java -


i need find lengths of multidimensional array non equal indices.

for example, have int[][] pathlist = new int[6][4]

without hard-coding indices, need find '6' , '4'.

i can find 6 pathlist.length how obtain '4'?

this give length of array @ index i

pathlist[i].length 

it's important note unlike c or c++, length of elements of two-dimensional array in java need not equal. example, when pathlist instantiated equal new int[6][], can hold 6 int [] instances, each of can different length.


so when create arrays way you've shown in question, may do

 pathlist[0].length 

since know have same length. in other cases, need define, specific application what length of second dimension means - might maximum of lengths elements, or perhaps minimum. in cases, you'll need iterate on elements , read lengths make decision:

for(int = 0; < pathlist.length; i++) {     int currlen = pathlist[i].length; } 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -