Java ArrayList Benchmark

Learn about ArrayList and LinkedList performance. In this article, we test creation, addition and iteration performance of these containers.

“Don’t mistake activity with achievement.”
― John Wooden

1. Introduction

Let us examine the performance characteristics of List Implementations – ArrayList and LinkedList. We perform the testing for a variety of list sizes from 100 items to 1M items. We use the JMH test harness to conduct the test on a single core machine. Results are presented below.

Continue reading “Java ArrayList Benchmark”

Java HashMap – Remove Entries

Learn about removing entries from a HashMap, including removing by key, with an iterator and bulk removal with a filter.

“To live is the rarest thing in the world. Most people exist, that is all.”
― Oscar Wilde


1. Introduction

After covering HashMap basics, iteration and searching/sorting, let us look at a few ways of removing entries from a HashMap.

Continue reading “Java HashMap – Remove Entries”

Java HashMap Search and Sort

Search and sort a HashMap by key as well as by value.

“What you stay focused on will grow.”
― Roy T. Bennett

1. Introduction

Having explored HashMap in several previous articles (here and here), let us now learn how to search and sort a HashMap by key as well as value.

Continue reading “Java HashMap Search and Sort”

Java Collections – HashMap

Create a HashMap by parsing CSV. Declare and use a multi-map (a HashMap inside a HashMap).

“Don’t judge each day by the harvest you reap but by the seeds that you plant.”
― Robert Louis Stevenson

Check out the previous parts of this Java Collections Guide: Introduction, Part 1 – Collection, Part 2 – Sets and Part 3 – ArrayList.

1. Introduction

The HashMap implements the Map interface and provides the abstraction of a dictionary mapping of keys to values. It is a part of the Java Collections Framework but does not fall under the Iterable and Collection hierarchy. In this article, we learn how to use HashMaps.

Continue reading “Java Collections – HashMap”

Java Collections – ArrayList

How to properly create and use an ArrayList including adding, retrieving and modifying items.

Check out the previous parts of this Java Collections Guide: Introduction, Part 1 – Collection and Part 2 – Sets.

1. Introduction

The ArrayList is one of the most widely used classes in the Java Collections Framework (if not the entire JDK; that position probably belongs to String). It provides a simple array-like storage of items with dynamically adjusting capacity. In this article, we present some usage patterns of the List and ArrayList.

Continue reading “Java Collections – ArrayList”

How to Convert CSV to JSON in Java

Convert CSV to JSON using Jackson. Use a POJO for conversion or a List & Map for intermediate storage.

“Any fool can know. The point is to understand.”
― Albert Einstein


1. Introduction

CSV to JSON conversion is easy. In this article, we present a couple of methods to parse CSV data and convert it to JSON. The first method defines a POJO and uses simple string splitting to convert CSV data to POJO, which in turn is serialized to JSON. The second method uses a more complete CSV parser with support for quoted fields and commas embedded within fields. In this method, we use the Java Collection classes to store the parsed data and convert those to JSON.

Continue reading “How to Convert CSV to JSON in Java”

Java Collections – Set

A Set is a container which does not allow duplicate elements. Common Set implementations include HashSet, LinkedHashSet and TreeSet.

“Quotation, n: The act of repeating erroneously the words of another.”
― Ambrose Bierce, The Unabridged Devil’s Dictionary

Check out the earlier parts of this Java Collections Series: Introduction and Part 1.

1. Introduction

A Set is a container which does not contain duplicate elements. The item method equals() is used to determine whether the object is already present in the Set. At most one null element is allowed in the Set.

Continue reading “Java Collections – Set”

Java Collections – Part 1

Java Collections Framework: learn about adding items, iterating over a collection and removing items.

“Success is not final, failure is not fatal: it is the courage to continue that counts.”
― Winston S. Churchill

Check out the first part of this Java Collections Series: Introduction.

1. Introduction

Let us learn about Java Collections and the various operations applicable to collections in general. Since the Collection interface is implemented by most of the classes in the Collections Framework (except Map and friends), the methods described here apply to all those classes.

Continue reading “Java Collections – Part 1”

Java Collections

Java Collections Framework: An Introduction to the class hierarchy.

“Any fool can know. The point is to understand.”
― Albert Einstein

1. Introduction

Java Collections Framework is an architecture for storing, managing and manipulating collections of objects. It provides many data structures and algorithms commonly used for dealing with collections. For example: searching and sorting. Many details about storing objects are abstracted away (meaning you do not have to deal with it in code). An unified interface is provided to manipulate them e.g for adding and removing entries.

Continue reading “Java Collections”