ArrayList retainAll() retains only the elements in this list that are contained in the specified method argument collection. Rest all elements are removed from the list. This method is exact opposite to removeAll() method. 1. ArrayList retainAll() method Internally, the retainAll() method iterate over all elements of arraylist. For each element, it pass element to […]
ArrayList removeAll() removes all of matching elements that are contained in the specified method argument collection. It removes all occurrences of matching elements, not only first occurrence.
ArrayList remove() removes the first occurrence of the specified element from this list, if it is present. If the list does not contain the element, list remain unchanged.
ArrayList listIterator() returns a list iterator over the elements in this list. It is a bi-directional iterator which is fail-fast in nature. By default, elements returned by the list iterator are in proper sequence. 1. ArrayList listIterator() method The listIterator() method is overloaded and comes in two variants: ListIterator listIterator() – Returns a list iterator […]
ArrayList forEach() method iterate the list and performs the argument action for each element of the list until all elements have been processed.