ArrayList lastIndexOf() Method in Java

ArrayList lastIndexOf() is used when there are multiple elements in list with the same value and you want to find the highest index position of that value. lastIndexOf() returns the largest index of the specified element from the ArrayList. If the specified element is not present then it returns -1. Read more…

ArrayList indexOf() Method in Java

ArrayList indexOf() method returns the index of the first occurrence of the specified element from the list or -1 if this list does not contain the element. Technically, it gives back the lowest index of the element from the list. You can call this method will null or custom object Read more…

ArrayList contains() Method in Java

ArrayList contains() method checks if the list has the specified element or not. Technically, it returns true only when the list contains at least one element where the following condition is met. (o == null ?  e== null : e.equals(o)), where e is each element in the list. You can Read more…

ArrayList size() Method in Java

ArrayList size() method returns the number of elements in this list. Syntax: Returns – number of elements in the ArrayList. ArrayList Size Example The below program shows how to use the size() method to check the number of elements in the list. Output: Size Example with User-Defined Object Here Employee Read more…

Java.util.ArrayList.set() Method

Java.util.ArrayList.set() method replaces the element at the specified index with the new element. Syntax: Let’s look the syntax of Java.util.ArrayList.set(). Parameters: index – This is the position of the element to be replaced, e – This is the element to be stored at the specified position. Returns: It returns the Read more…

Java.util.ArrayList.get() Method

The java.util.ArrayList.get(int index) method returns the element at the specified index or position. Syntax: Let’s look at the syntax of ArrayList.get(int index). Parameter: The index is the position of the element to be returned. E – The actual element to return. Exception: IndexOutOfBoundsException – If the index is out of Read more…

ArrayList addAll() Method in Java

In this post, we will look at what ArrayList addAll() method does and how to use it. We will also look at the programs to demonstrate their usage. If you want to add multiple elements to the ArrayList then the best option is to use the addAll() method. What ArrayList Read more…

Java.util.ArrayList.add() Method

ArrayList add(int index, E element) method inserts the element E at the specified index. As a result, the element at that position and any subsequent elements are shifted to the right by 1 position in the List. Syntax: Following are the variations of the add() method. It returns true on Read more…