Notes
In Apex, the clone()
method is used to create a shallow copy of a list. This means that a new list is created, and the elements in the new list refer to the same objects as the elements in the original list. However, the lists themselves are separate instances.
Here's an example of using the clone()
method with a list:
List<String> originalList = new List<String>{'apple', 'banana', 'cherry'};
List<String> clonedList = originalList.clone();
clonedList.add('orange');
System.debug('Original List: ' + originalList);
System.debug('Cloned List: ' + clonedList);
Output:
Original List: (apple, banana, cherry)
Cloned List: (apple, banana, cherry, orange)
Video
Video does not exists.