Yes, assignment will just copy the value of l1
(which is a reference) to l2
. They will both refer to the same object.
Creating a shallow copy is pretty easy though:
List<Integer> newList = new ArrayList<>(oldList);
(Just as one example.)
More Related Contents:
- ArrayList is reinitialising when a method is called
- why is it that we can’t use ArrayList.get(-1) to get the last element of the ArrayList in java? it works in python though [closed]
- How to arrange the datas to display in array by given string of days in java?
- ArrayList Data Structure – Daily Temperature
- I am new in using ArrayLists. Array Out of Bounds, Array seems to be empty, but have been adding Strings to it already
- When to use LinkedList over ArrayList in Java?
- Convert ArrayList to String[] array [duplicate]
- How to count the number of occurrences of an element in a List
- In Java how do you sort one list based on another?
- How to iterate an ArrayList inside a HashMap using JSTL?
- Sorting arraylist in alphabetical order (case insensitive)
- How can I create an Array of ArrayLists?
- ArrayList’s custom Contains method
- Get specific ArrayList item
- Best way to create a hashmap of arraylist
- How to remove element from ArrayList by checking its value?
- How do I populate a JComboBox with an ArrayList?
- How to find the length of an array list? [duplicate]
- How can I slice an ArrayList out of an ArrayList in Java?
- How can I convert ArrayList to ArrayList?
- Trying to find all occurrences of an object in Arraylist, in java
- casting Arrays.asList causing exception: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayList
- How can I create an array in Kotlin like in Java by just providing a size?
- Time complexity of contains(Object o), in an ArrayList of Objects
- How to remove specific object from ArrayList in Java?
- How to change value of ArrayList element in java
- In Java, can you modify a List while iterating through it?
- How to merge two ArrayLists without duplicates? [duplicate]
- Why do I need to synchronize a list returned by Collections.synchronizedList
- Add ArrayList to another ArrayList in java