How can i initialize an array without knowing it size?
Posted
by
Sara
on Stack Overflow
See other posts from Stack Overflow
or by Sara
Published on 2010-12-26T18:50:04Z
Indexed on
2010/12/26
18:53 UTC
Read the original article
Hit count: 203
java
I have a situation where i have to apply a criteria on an input array and reuturn another array as output which will have smaller size based upon the filtering criteria.
Now problem is i do not know the size of filtered results, so i can not initialize the array with specific value. And i do not want it to be large size will null values because i am using array.length; later on.
One way is to first loop the original input array and set a counter, and then make another loop with that counter length and initialize and fill this array[]. But is there anyway to do the job in just one loop?
© Stack Overflow or respective owner