Notes
In Apex, the clear()
method is used to remove all elements from a list, leaving it empty. It's a convenient way to reset or clear the contents of a list without having to iterate through and remove each element individually.
Here's an example:
List<Integer> numberList = new List<Integer>{1, 2, 3, 4, 5};
System.debug('Original List: ' + numberList);
numberList.clear();
System.debug('List after clearing: ' + numberList);
Output Before Clear: Original List: (1, 2, 3, 4, 5)
Output After Clear: List after clearing: ()
Video
Video does not exists.