Let's say that I have an ArrayList of class Person and I have two objects that are generated from two different classes which read and write to this ArrayList.For example,public class Main {    public static void main(String[] args) {        A a = new A();       B b = new B();   }}What, in your opinion is the best design to handle this ArrayList. I can think about two options:create the Array List in class Main:public class Main {    public static ArrayList<Person> list = new ArrayList<>();   public static void main(String[] args) {        A a = new A();       B b = new B();   }}and then access the list inside classes A and B via Main.list.Create the ArrayList as a local variable in main method and send to the constructor of A and B.public class Main {    public static void main(String[] args) {        ArrayList<Person> list = new ArrayList<>();         A a = new A(list);        B b = new B(list);    }}public class A {     private ArrayList<Person> list;    public A(ArrayList<Person> list) {        this.list = list;    }}and then list is an attribute of objects A and B.
What is a best design to hold a global mutable list?
design;design patterns;object oriented design;static
With option 1 your list is actually global mutable state which is usually regarded as a Bad Thing. Passing dependencies to constructors as you do in option 2 is the right thing to do.There could be issues with your option 2 like concurrency as mentioned by Laiv in a comment, main could not be the best place for this code or you might want to use factories to instantiate A or B to name a few, but you didn't provide enough context to assess these potential problems. As it is written, option 2 looks fine to me.