Say i have the array
int theArray = new int[20];
The length of the array is 20 but the count is 0. How can i get the count?
What do you mean by "the count"? The number of elements with a non-zero value? You'd just have to count them.
There's no distinction between that array and one which has explicitly been set with zero values. For example, these arrays are indistinguishable:
int[] x = { 0, 0, 0 };
int[] y = new int[3];
Arrays in Java always have a fixed size - accessed via the length
field. There's no concept of "the amount of the array currently in use".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With