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)
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)
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.