List addAll() Method in Java

addAll(Collection c) method of List appends all the elements of the specified collection to the end of the List instance. The specified collection’s iterator defines the order of added elements. The behavior of this method is undefined if someone modifies the supplied collection during this operation. Syntax: Let’s look at Read more…

Java 14 NullPointerException Detailed Message

NullPointerException is something which every developer faces and it is difficult to find where the exception occurred. Java 14 made it really convenient for programmers to find the NullPointerException in the code. It adds a really good description specifying where the exception occurred along with the variable name. Let’s look Read more…

Sort ArrayList Elements in Descending Order Java

In this article, we will see how to sort ArrayList elements in descending order using sort(List list, Collections.reverseOrder()) method. Examples: Input:    23, 54, 32, 56, 78, 65 Output: 78, 65, 56, 54, 32, 23 Input:    Microsoft, Vmware, Salesforce, Apple, Facebook Output: Vmware, Salesforce, Microsoft, Facebook, Apple Example 1: Read more…

ArrayList isEmpty() Method in Java

ArrayList isEmpty() checks if the list is empty or not. If returns true if the list is empty else false it returns false. Syntax: This method doesn’t throw any exceptions. Let’s try to understand this diagrammatically understand isEmpty() behavior. Program to demonstrate ArrayList isEmpty() Let’s have a look at the Read more…

ArrayList removeAll() Method in Java

ArrayList removeAll() is used to remove all the elements contained in the specified collection from the list. It throws NullPointerException if the specified collection is null. Syntax: Parameter – c is the collection of elements to be removed from the list. Returns – true if the list changed as a Read more…

ArrayList remove() Method in Java

The remove() method of ArrayList removes the specified element from the list. We can also remove an element at a particular position using remove(int index). It throws IndexOutOfBoundsException if the index is out of range. Syntax: Parameters – o is the element to be removed. Returns – true on successful Read more…