The contains() method of java.util.ArrayList class returns true if this list contains the specified element. … [Read more...]
How to swap elements in an ArrayList
In this tutorial we will learn how to swap elements of an ArrayList, we will be using Collections.swap() method to achieve sorting. Swapping the elements of the ArrayList Create a new arraylist arraylist al1. Add elements to al1 using add() method. Use Collections.swap() method to swap the required elements of al1. … [Read more...]
How to join two ArrayLists in java
In this article we will learn how to combine two ArrayList in Java. We will be using the help of addAll() method of ArrayList class. Lets see how we can achieve it. … [Read more...]
Override toString() method of ArrayList in Java
When we are working with ArrayList of Objects then it is must that we have to override toString() method of Java ArrayList to get the output in the desired format. Lets learn how to override toString() method. … [Read more...]
Find Common Elements between two ArrayList in Java
In this tutorial we will learn how to get the common elements between two ArrayList. We would be using removeAll() method to retain only the common elements between two lists. public boolean removeAll(Collection<?> c) It removes all the elements in the list that are not contained in the specified list. … [Read more...]
Java ArrayList indexOf(Object o) Method Example
In this tutorial we will learn how to use indexOf(Object o) method of java.utilArrayList class. This method is used for finding the index of a particular element in the list. … [Read more...]