Link to home
Start Free TrialLog in
Avatar of cmdolcet
cmdolcetFlag for United States of America

asked on

How to determine if an arraylist item has been populated

I need to figure out where in my arraylist i am currently to populate it with an additional item.

I have an arraylist of size 8. I fill my first item slot and then do something else. I need to be able to check that item slot see if it is filled and then populate the next item slot.

I know the arraylist has a count. But thats not what im looking for.
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

An ArrayList grows dynamically when you add to it so unless you've explicitly added Nothing to it multiples time you don't need to track the "next slot".  If you are specifying an initial CAPACITY in the constructor then this controls the INTERNAL size of the ArrayList so it doesn't need to change its internal size to accommodate new items.

Even with an initial capacity, the ArrayList does NOT have anything it!  If you know how many items you are going to insert beforehand then you can set capacity and the Arraylist will not have to increase in size INTERNALLY to hold the items.

Does that make sense at all?
Avatar of cmdolcet

ASKER

i do understand and I have gone about creating an initial size in a constructor. However in saying that the arraylist will fill up each time a timer is fired.

For example:

first pass -

slot 0: data is populated in the slot
slot 1:
slot 2:
slot 3:
slot 4:
slot 5:
slot 6:
slot 7:

Once data is populated the arraylist is exited and is saved.
On the next entry pass 2.




second pass after the
slot 0: data from pass 1
slot 1: data is populated in the slot
slot 2:
slot 3:
slot 4:
slot 5:
slot 6:
slot 7:

once the second slot is filled it will exit the routine.
SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial