I’m a beginner with java and I wanted to know if there was a way to dynamically instantiate an array, that is, being able to add and remove elements by changing the actual size of the array.
>Solution :
In java there is a class called Arraylist,
to import it import java.util.ArrayList;
you have to declare it with the data type you want it to contain an example below with some strings
ArrayList <String> cars = new ArrayList <String> ();
To add an item just use the .add (item) function like this
cars.add ("Tesla");
to remove instead it is necessary to have the index and with the command .remove (index)
you can remove an object
cars.remove(0);