Java, How does add to an arraylist work -


I've been trying to get more acquainted with Java recently I got a question that I did not find an answer online. I'm wondering when Java is an arraylist that adds an element, the added element is an element associated with the variable? For example, in the following code:

  e obj1 = new E (); E obj2 = new E (); List myList = new arrelisted & lt; E & gt; (); MyList.add (obj1); Obj1 = obj2;   

After the new assignment for obj1 will the value be present in myList change or not?

No, when you add an object to a list , The reference is copied and so when you assign obj1 with the new value, the list will be outdated.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -