trimToSize() method is used for memory optimization. It trims the capacity of ArrayList to the current list size. For e.g. An arraylist is having capacity… [Read More]
Java ArrayList remove(Object obj) Method example
The method remove(Object obj) removes the specified object from the list. It belongs to the java.util.ArrayList class. public boolean remove(Object obj) Note: It returns false… [Read More]
Java ArrayList remove(int index) Method example
Method remove(int index) is used for removing an element of the specified index from a list. It removes an element and returns the same. It… [Read More]
Java ArrayList lastIndexOf(Object 0bj) Method example
The method lastIndexOf(Object obj) returns the index of last occurrence of the specified element in the ArrayList. It returns -1 if the specified element does… [Read More]
Java ArrayList isEmpty() Method example
isEmpty() method of java.util.ArrayList class is used for checking whether the list is empty or not. This method returns a boolean value. public boolean isEmpty()… [Read More]
Java ArrayList ensureCapacity() Method example
ArrayList internally implements growable dynamic array which means it can increase and decrease its size automatically. If we try to add an element to a… [Read More]
Java ArrayList indexOf() Method example
Java.util.ArrayList class method indexOf(Object o) is used to find out the index of a particular element in a list. Method indexOf() Signature public int indexOf(Object… [Read More]
Java ArrayList get() Method example
ArrayList get(int index) method is used for fetching an element from the list. We need to specify the index while calling get method and it… [Read More]
Java ArrayList contains() Method example
ArrayList contains() method is used for checking the specified element existence in the given list. public boolean contains(Object element) It returns true if the specified… [Read More]
Java ArrayList addAll(int index, Collection c) Method example
In the last tutorial we have shared the example of addAll(Collection c) method which is used for adding all the elements of Collection c at the… [Read More]
Java ArrayList addAll(Collection c) Method example
In this tutorial we will see the usage of addAll() method of java.util.ArrayList class. This method is used for adding all the elements of a… [Read More]
Java ArrayList add(int index, E element) example
Simple add() method is used for adding an element at the end of the list however there is another variant of add method which is… [Read More]
Java ArrayList add Method with Examples
The add() method of Java ArrayList class is used to add elements to an ArrayList. In this guide, we will see various examples of add… [Read More]
How to compare two ArrayList in Java
In this tutorial we will learn how to compare two ArrayList. We would be using contains() method for comparing two elements of different ArrayList. public… [Read More]
How to override toString method for ArrayList in Java
When we are dealing with ArrayList of Objects then it is must to Override the toString() method in order to get the output in desired… [Read More]