Flattening Nested Collections in Java 1. Overview In this quick article, we’ll explore how to flatten a nested collection in Java. 2. Example of a Nested Collection Suppose we have a list of lists of type String. List<List<String>> nestedList = asList( asList(“one:one”), asList(“two:one”, “two:two”, “two:three”), asList(“three:one”, “three:two”, “three:three”, “three:four”)); 3.… Continue Reading java-flatten-nested-collections

Multi Dimensional ArrayList in Java 1. Overview Creating a multidimensional ArrayList often comes up during programming. In many cases, there is a need to create a two-dimensional ArrayList or a three-dimensional ArrayList. In this tutorial, we’ll discuss how to create a multidimensional ArrayList in Java. 2. Two-Dimensional ArrayList Suppose we want to represent… Continue Reading java-multi-dimensional-arraylist

Extending an Array’s Length 1. Overview In this tutorial, we’ll take a look at the different ways in which we can extend a Java array. Since arrays are a contiguous block of memory, the answer may not be readily apparent, but let’s unpack that now. 2. Using Arrays.copyOf First, let’s… Continue Reading java-array-add-element-at-the-end

Filtering a Java Collection by a List 1. Overview Filtering a Collection by a List is a common business logic scenario. There are plenty of ways to achieve this. However, some may lead to under-performing solutions if not done properly. In this tutorial, we’ll compare some filtering implementations and discuss… Continue Reading java-filter-collection-by-list