I have one doubt in java, can we create dynamic ArrayList or String[] inside a for-loop. For example in my app there are categories field is there (not static, obtaining from server), I want to create ArrayList or String[] object based on size of categories. How can I create a dynamic ArrayList in side a loop?
My code is as follows:
for(int i =0; i<20; i++)
{
ArrayList <String> list(i) = new ArrayList<String>();
}
can we create an object like this? based on category position, I can call the list items like list(positon), can we do like this java?
ArrayList is a dynamic array, i.e. you can add new elements like,
ArrayList <String> list = new ArrayList<String>();
for(int i =0; i<20; i++)
{
list.add("string"+i);
}
i can call the list items like list(positon),can we do like this java?
ArrayList have get(position) method to get Object from position.
String str1 = list.get(0);//0th position
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With