Like I set a size, but how do i check if the array still have more room?
3 Replies - 619 Views - Last Post: 06 April 2011 - 03:50 PM
Replies To: How do I check if my array still have more room ?
#2
Re: How do I check if my array still have more room ?
Posted 06 April 2011 - 11:37 AM
What do you mean?
Post an example in code.
Post an example in code.
#3
Re: How do I check if my array still have more room ?
Posted 06 April 2011 - 02:56 PM
vienhuynh, on 06 April 2011 - 01:33 PM, said:
Like I set a size, but how do i check if the array still have more room?
No way. An array is always full. Aka all the slots are occupied.
You will have to handle to use a counter by yourself to count where you are.
int[] array = new int[10];
int nbInUse = 0;
....
array[nbInUse++] = 10;
array[nbInUse++] = 20;
array[nbInUse++] = 30;
if(array.length == nbInUse) ... no more slots
#4
Re: How do I check if my array still have more room ?
Posted 06 April 2011 - 03:50 PM
To expand some, with Objects, all the elements are initialized to null. You can think of those slots as "empty" because they do not reference any Objects in memory. Arrays of primitive types are initialized to default values (0 for numbers and chars, and false for booleans). Those have actual values, and cannot be thought of as "empty" in the same way as with Objects. You'll still have to use a counter to keep track of the number of elements, as pbl described.
Hope this helps some.
Hope this helps some.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote






|