Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

Can anyone tell me how to dynamically size the array as the program executes in Java? 

1 Answer

0 votes
by (19.7k points)

Yes, you can use ArrayList. It’ll allocate the size dynamically as per the run time. You’ve to import ArrayList from ‘import java.util.ArrayList;’

Below is the code implementation of ArrayList creation: 

ArrayList<int> numbers = new ArrayList<int>(); 

numbers.add(“1”);

numbers.add(“2”);

numbers.add(“3);

System.out.println(numbers);

 If you want to learn more about Javathen go through this Java tutorial by Intellipaat for more insights.

Browse Categories

...