num elements in an array

Is it possible to get the number of elements in an array.

byte[] b = new byte[10];

b.length gives 10. Thats true, but I want the no of elements inserted in the array. (currently 0)

[199 byte] By [the_learnera] at [2007-11-27 10:27:39]
# 1

The only way to do this is to have a variable that keeps count for you. So whenever you add an element to the array you increment the counter and decrement it when you remove an element.

floundera at 2007-7-28 17:47:00 > top of Java-index,Java Essentials,Java Programming...