OneBite.Dev - Coding blog in a bite size

find the length of an array in java

Code snippet on how to find the length of an array in java

int[] array = {1,2,3,4}; 

int arraySize = array.length;

This code snippet uses an array of numbers to demonstrate how to find the length of an array in Java. First, we define the array variable, “array”, and set the value to an array of four integers: {1,2,3,4}. Then, we create a new variable, “arraySize”, and set the value to the length of the array, which we can access using the .length property. Finally, the value of “arraySize” will be equal to 4 once this code has been executed.

java