Coding in java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Coding in java

How can i add new string into an array of strings like if i have a library class and i create an array of books and i want to add new book object into this array ( the max size is 50)

22nd Oct 2019, 7:55 PM
Nada Kolaghaci
Nada Kolaghaci - avatar
2 Answers
+ 3
It sounds like you might be looking for something more like an ArrayList. Import it from the until package: import java.util.ArrayList; You can declare an ArrayList of Strings like this: ArrayList<String> myList = new ArrayList<String>(); From there, you can add and remove objects as you need. Using the respective ArrayList#add(E e) and ArrayList#remove(int index) methods. Also, I wrote an implementation of it if you would like to see how it works behind the scenes. https://code.sololearn.com/cwZPj045S2Fr/?ref=app
22nd Oct 2019, 8:00 PM
Brian R
Brian R - avatar
0
thank you , but i didn't take this method so i didn't want to get copy without understanding it :)
23rd Oct 2019, 9:00 PM
Nada Kolaghaci
Nada Kolaghaci - avatar