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.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
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?
cmdolcetAuthor Commented:
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.
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
The capacity controls the INVISIBLE (to you) size of the array maintained by the ArrayList itself.  You cannot see it or access it.  If you pass in an initial size then the internal array will have that many slots...BUT from an outside perspective, it is EMPTY.  So on the first Timer Tick you simply call Add(something) and it will go into the first slot.  On the second Tick you call Add(something) again and it will go into the second slot (next available slot).  When you attempt to add something and the internal array is full then the ArrayList will grow the internal array so there is more room.  This is a slow operation as the contents of the array have to be copied to the new bigger array.  By setting an initial capacity you can prevent the slow operation of "growing" when you know beforehand that you will be adding a bunch of items to the ArrayList.

Are you explicitly "pre-filling" the ArrayList with Nothing using a loop?
If yes, then you would need to find the next available slot.
If no, then you simply call the Add() method and the next available slot is used.

If you simply declared the ArrayList with an initial capacity then you do not need to do anything special...just Add() to it!

If this doesn't seem to apply to your situation then show us some code and maybe that will clear up any confusion...  =)
Are you sure you are using arraylist and not just an array? Are you using Insert instead of Add?

Declare and use a class level variable "CurrentIndex" which keeps track of the currently populated value. With every pass, increment the value until it reaches the end.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.