CollectionUtils selectRejected method

In this post under Apache Collections, I will show with example the use of “selectRejected” method. “selectRejected” is a static method available under “CollectionUtils” class. It takes two arguments1) input collection2) predicate In this method, the predicate is evaluated on each item of the collection and a new collection is returned which contains items from…… Continue reading CollectionUtils selectRejected method

CollectionUtils select method

In this post under Apache Commons Collections, I will explain with example the purpose of “select” static method in “CollectionUtils” class. This method is basically used to filter the collection based on defined predicate. Below is an example of its usage Main class package defaultPackage; import org.apache.commons.collections4.CollectionUtils; import java.util.ArrayList; import java.util.List; public class Example17 {…… Continue reading CollectionUtils select method

Reversing an array

In this post under Apache Collections, I will explain with example how to reverse a given array. Apache Collections framework “CollectionUtils” class provide a static method named “reverseArray” which can be used to reverse an array. Below is the main class showing its usage. Main Class package defaultPackage; import org.apache.commons.collections4.CollectionUtils; import java.util.Arrays; public class Example16…… Continue reading Reversing an array

CollectionUtils retainAll method

In this post under Apache Collections, I will show with example the purpose of “retainAll” method under “CollectionUtils” class. The “retainAll” method takes two collections say “collection1” and “collection2” as arguments and returns a new collection. The new collection will only contain elements that are present both in “collection1” and “collection2”. Lets see a main…… Continue reading CollectionUtils retainAll method

CollectionUtils removeAll method

In this post under Apache Collections, I will explain with example the purpose of “CollectionUtils” class “removeAll” method. This method takes two collections i.e, “collection1” and “collection2” as an arguments. This method searches for elements in “collection2” in “collection1”. If the element is found in “collection1”, it is removed. Basically, it returns a collection say…… Continue reading CollectionUtils removeAll method

Permutations of collection elements

In this post under Apache collections, I will explain with example, how to generate a collection of possible permutations of a particular collection elements. If we have collection of elements, we can generate a list of different permutations containing the same elements. The Apache Collections tool, has a “permutations” method in “CollectionUtils” class. This method…… Continue reading Permutations of collection elements

Comparing two collections for equality

In this post under Apache Collections, I will show with example how to compare two collections for equality. We consider two collections are equal if they have same elements repeated same number of times. The Apache Collections tool has “isEqualCollection” method on “CollectionUtils” class which we can use to compare two collections for equality. Below…… Continue reading Comparing two collections for equality

CollectionUtils getCardinalityMap method

In this post under Apache Collections, I will explain with example, the purpose of CollectionUtils “getCardinalityMap” method. This method takes a collection as an argument and returns a map. A map where key is an element from the collection, and value will be the number of times the element is repeated in the collection. So…… Continue reading CollectionUtils getCardinalityMap method

CollectionUtils intersection method

In this post under Apache Collections, I will explain with example the purpose of CollectionUtils “intersection” method. The “intersection” method compares two collections and return a new list containing items that are common in both of them. Below is the complete main code for your reference. Main class 1 package defaultPackage; 2 3 import org.apache.commons.collections4.CollectionUtils;…… Continue reading CollectionUtils intersection method

CollectionUtils containsAny method

In this post under Apache Collections, I will explain with example the purpose of CollectionUtils “containsAny” method. This method is used to compare two collections. It returns true if both the collections has atleast one element in common or else false. Below is the main class for your reference Main class 1 package defaultPackage;2 3…… Continue reading CollectionUtils containsAny method