List<List<Citizen>> mainList= new ArrayList<>();
You can go with List of List.
Also need to consider below points.
I recommend using "List"
instead of "ArrayList"
on the left side when creating list objects. It’s better to pass around the interface "List"
because then if later you need to change to using something like Vector (e.g. you now need synchronized lists), you only need to change the line with the “new” statement. No matter what implementation of list you use, e.g. Vector or ArrayList
, you still always just pass around List.
In the ArrayList constructor, you can leave the list empty and it will default to a certain size and then grow dynamically as needed. But if you know how big your list might be, you can sometimes save some performance. For instance, if you knew there were always going to be 500 lines in your file, then you could do:
3
solved is there a way to have a “main” arraylist? [closed]