There are two ways to empty an ArrayList – By using ArrayList.clear() method or with the help of ArrayList.removeAll() method. Although both methods do the same… [Read More]
How to synchronize ArrayList in java with example
We have already discussed a bit about synchronization when we shared the tutorial on Vector vs ArrayList. As we are aware that ArrayList is non-synchronized… [Read More]
How to swap two elements in an ArrayList
This tutorial will help you understand how to swap two elements in an ArrayList. We are using Collections.swap() method for swapping. public static void swap(List… [Read More]
How to get sublist of an ArrayList with example
In this tutorial, we will see how to get a sublist from an existing ArrayList. We will be using the subList() method of ArrayList class…. [Read More]
ArrayList clone() method in Java
In this tutorial, we will see examples of ArrayList clone() method. This method creates a shallow copy of an ArrayList. Syntax: newList = oldList.clone() Creates… [Read More]
Copy Elements of One ArrayList to Another ArrayList in Java
In this tutorial, we will write a java program to copy elements of one ArrayList to another ArrayList in Java. We will be using addAll()… [Read More]
TreeMap in Java with Example
TreeMap is Red-Black tree based NavigableMap implementation. It is sorted according to the natural ordering of its keys. TreeMap class implements Map interface similar to… [Read More]
Difference between ArrayList and LinkedList in Java
In this guide, you will learn difference between ArrayList and LinkedList in Java. ArrayList and LinkedList both implements List interface and their methods and results… [Read More]
Difference between ArrayList and Vector in Java
ArrayList and Vector both use Array as a data structure internally. However there are key differences between these classes. In this guide, you will learn… [Read More]
Vector in Java
Vector implements List Interface. Like ArrayList it also maintains insertion order but it is rarely used in non-thread environment as it is synchronized and due to… [Read More]