Reputation: 1
I am using an input file to populate my array with different strings. how do I check up to where the array is filled? I initialize the size of my array to 30000, but how do I check up to which index it contains a string?
Thank you for your help!
Upvotes: 0
Views: 609
Reputation: 7290
Low-level approach: while populating the array, maintain a count
variable, adding 1 to it on every element you insert into the array.
Professional approach: instead of an array, use a java.util.List
, e.g. a java.util.ArrayList
. List instances do the counting for you (and by the way, don't waste 25000 empty elements if your file only contains 5000).
Upvotes: 1