How To Get The Length Of An Array In Java
Chapter:
Miscellaneous
Last Updated:
27-05-2023 12:52:01 UTC
Program:
/* ............... START ............... */
int[] myArray = {1, 2, 3, 4, 5};
int length = myArray.length;
System.out.println(length);
/* ............... END ............... */
Output
Notes:
-
In the example above, myArray.length returns the length of the myArray array, which is 5. The length property is available for arrays of any type in Java. Note that in Java, length is a property, not a method, so you don't need to use parentheses when accessing it.
Tags
How to get the length of an array in java, Array length in Java