This tutorial focuses in how to determine the array size in java. Arrays are one of the most overused storage of information in java since the declaration is easy and a lot of API’s requires this collection as an input and also as an output. Basically it holds a list of information whether its only a strings or complicated lists of objects. Focus on this knowledge, since we would be using it thoroughly on our programming life. However, I prefer more to use ArrayList since it is more flexible and has a lot more functions that is necessary on my everyday programming. But don’t get me wrong, in order to understand the much more complicated API, we should master first all the important concepts of an array.

On this article we would be focusing on determining how large is our array is. This is very important to learn since we would be using it in our loops especially if the java codes we are maintaining are still not using the advance for loop. The size is necessary to determine the upper bound of the index we should be looping in. Moreover, the size of an array might also be necessary on your business requirements.

JAVA examples : API needed in getting the array size in java

  • length – its an attribute of an array giving the current size

Java array example source code

Sample Output: