Get ArrayList elements

We can use get(int index) method for retrieving the element from list It returns the value present at the specified index This method throws IndexOutOfBoundsException if the index is less than zero or greater than the size of the list Example 1 : import java.util.ArrayList; import java.util.List; public class ArrayListGetElement {     public static […]

Share this article on

Remove ArrayList elements

We can use remove() method of ArrayList to delete/remove elements from ArrayList There are 4 overloaded “remove” methods defined in ArrayList 1) Object remove(int index); 2) boolean remove(Object o); 3) boolean removeAll(Collection c); 4) protected void removeRange(int fromIndex, int toIndex); 1) Object remove(int index) Removes the element at the specified position in the list. Example […]

Share this article on
< Previous Next >