1.

How To Remove Elements From An Arraylist?

Answer»

ArrayList provides several methods to remove elements from the LIST. Since ArrayList internally uses array to store elements, one point to note is that when an element is removed from the List the remaining elements have to be shifted to fill the GAP created in the underlying array.

  • clear() - Removes all of the elements from this list.
  • remove(int INDEX) - Removes the element at the SPECIFIED position in this list.
  • remove(Object o) - Removes the first occurrence of the specified element from this list, if it is present.
  • removeAll(Collection<?> c) - Removes from this list all of its elements that are contained in the specified collection.
  • removeIf(Predicate<? super E> filter) - Removes all of the elements of this collection that SATISFY the given predicate.

ArrayList provides several methods to remove elements from the List. Since ArrayList internally uses array to store elements, one point to note is that when an element is removed from the List the remaining elements have to be shifted to fill the gap created in the underlying array.



Discussion

No Comment Found