ClassCastException: Arrays$ArrayList cannot be cast to ArrayList 1. Introduction ClassCastException is a runtime exception raised in Java when we try to improperly cast a class from one type to another. It’s thrown to indicate that the code has attempted to cast an object to a related class, but of which… Continue Reading java-classcastexception-arrays-arraylist

Performance of contains() in a HashSet vs ArrayList 1. Introduction In this quick guide, we’re going to discuss the performance of the contains() method available in java.util.HashSet and java.util.ArrayList. They are both collections for storing and manipulating objects. HashSet is a collection for storing unique elements. To learn more about the HashSet,… Continue Reading java-hashset-arraylist-contains-performance

Remove All Occurrences of a Specific Value from a List 1. Introduction In Java, it’s straightforward to remove a specific value from a List using List.remove(). However, efficiently removing all occurrences of a value is much harder. In this tutorial, we’ll see multiple solutions to this problem, describing the pros… Continue Reading java-remove-value-from-list

Java ArrayList vs Vector 1. Overview In this tutorial, we’re going to focus on the differences between the ArrayList and Vector classes. They both belong to the Java Collections Framework and implement the java.util.List interface. However, these classes have significant differences in their implementations. 2. What’s Different? As a quick… Continue Reading java-arraylist-vs-vector

An Introduction to Synchronized Java Collections 1. Overview The collections framework is a key component of Java. It provides an extensive number of interfaces and implementations, which allows us to create and manipulate different types of collections in a straightforward manner. Although using plain unsynchronized collections is simple overall, it… Continue Reading java-synchronized-collections