Skip to content
Advertisement

Load an ArrayList with nested ArrayLists from a file using Java

I have an arraylist like ArrayList<ArrayList<String>>. I have saved my main ArrayList in a text file by using the following code.

JavaScript

Now, I want to load the saved data from the file to the same ArrayList ar2 in every new run. I tried several methods but the nested arraylists are loaded as Strings. How can I overcome from this issue?

Advertisement

Answer

Read the file contents, split by line separator and then remove the brackets and split again to get the list items. Something like

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement