Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

There is a method to dinamically change the size of array in java

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading