An Array in Java can hold arbitrary number of elements, depending on how the array object was created. The getLength() method of Array class returns the length of the specified array object, as an int. How to find the length of the multidimensional array in Java? So simply writing a few lines of code solves this problem. Java ‘length’ Attribute. long array[] = new long[5]; Arrays.fill(array, 30); The method also has several alternatives which set a range of an array to a particular value: It uses Arrays.copyOf which gives the array increased to the new length by right shift operator also it will grow by 50% of old capacity. Java Array getLength() Method. Syntax ‘length’ gives the number of elements allocated, not the number inserted. To find out how many elements an array has, use the length property: Example The grow method in the ArrayList class gives the new size array. The java.util.Arrays class has several methods named fill() which accept different types of arguments and fill the whole array with the same value:. So here’s a loop: int i=0; while (i