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: To declare an array, define the variable type with square brackets: String[] cars; We have now declared a variable that holds an java array of strings. The getLength() method of Array class returns the length of the specified array object, as an int. To find the length of an array, use array data member 'length'. The length is an in-built property of the array variable, which stores the information about the number of elements in the array. Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value. To perform operations on array, it is fundamental to know it's length. Java Array Length Examples. The number of elements in the array during declaration is called the size or length of the array. Whenever we initialize an array then by default length property is assigned to the array and we can access them through arrayVariable.length. Java Arrays. An Array in Java can hold arbitrary number of elements, depending on how the array object was created. 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:. Given an array named ‘myArray’, the length of the array is given by the following expression. Java Array getLength() Method. Array Length. This Java String Array Length example shows how to find number of elements contained in an Array. So here’s a loop: int i=0; while (i