A ListIterator allows traversal of a Java ArrayList in forward or backward direction.
“A man devoid of hope and conscious of being so has ceased to belong to the future.”
― Albert Camus, The Myth of Sisyphus and Other Essays
Java’s ArrayList class provides a list iterator which allows, among other things, traversal of the list in either direction. This is in comparison to a normal Iterator that allows traversal of the list in forward direction only. In this article, we delve into the usage and behavior of the ListIterator when used with an ArrayList.
Continue reading “Using Java ArrayList’s List Iterator”
Easily search a java list using java 8 predicate functions.
“Make improvements, not excuses. Seek respect, not attention.”
― Roy T. Bennett, The Light in the Heart
Searching, sorting and iterating are some of the fundamental operations required when using a list. Searching refers to finding one or more objects in the list that match a given condition. In this article, we look at some methods for searching a list in java.
Continue reading “Searching a List in Java”
Learn how to sort a List in java. Use Java 8 Lambdas to compose sort conditions.
“You can only be afraid of what you think you know.”
― Jiddu Krishnamurti
Sorting a list is a very common requirement when programming in java. Out of the box, java provides for sorting using a performant algorithm so there is no need to roll your own algo for the purpose. In this article, we demonstrate how to sort a list in java.
Continue reading “Sorting Lists in Java”
Learn how to use Jackson Streaming to convert a large CSV to JSON.
“We are a way for the cosmos to know itself.”
― Carl Sagan, Cosmos
Let us today look into converting a large CSV to JSON without running into memory issues. This previous article showed how to parse CSV and output the data to JSON using Jackson. However, since that code loads the entire data into memory, it will run into issues loading large CSV files such as:
Continue reading “How to Convert Large CSV to JSON”
Learn how to use the Timer and the TimerTask classes to implement simple task scheduling for your application.
“Humor is reason gone mad.”
― Groucho Marx
Scheduling tasks to run is a need which sometimes arises in a java program. Maybe you want to run periodic cleanup of some resource. Or check on the status of some job. Or maybe fetch a URL which might not be available the first time.
Continue reading “Using Timer Class to Schedule Tasks”
Implement a Pivot Table in Java using Java 8 Streams and Collections.
“Money may not buy happiness, but I’d rather cry in a Jaguar than on a bus.”
― Françoise Sagan
Today let us see how we can implement a pivot table using java 8 streams. Raw data by itself does not deliver much insight to humans. We need some kind of data aggregation to discern patterns in raw data. A pivot table is one such instrument. Other more visual methods of aggregation include graphs and charts.
Continue reading “Java – Pivot Table using Streams”
Learn the basics of regular expression pattern matching in Java. Covers a few basic regular expression constructs.
“Life’s under no obligation to give us what we expect.”
― Margaret Mitchell
Regular Expressions are the bread and butter of string pattern matching. They allow you to express a search pattern in general terms without being too specific about what you are searching for.
This article covers the basics of string pattern matching using regular expressions.
Continue reading “Java Regex – Simple Patterns”
Sorting a large CSV file by loading it into SQLite. Much faster and easier to process.
“When you’re at the end of your rope, tie a knot and hold on.”
― Theodore Roosevelt
We are trying to sort a large CSV file. The file contains a couple of million rows – not large by “big-data” standards, but large enough to face problems working with it.
Continue reading “Sort Large CSV File using SQLite”
Large CSV files present a challenge when need arises to sort. Learn how to do that using a database.
“All of life is a constant education.”
― Eleanor Roosevelt, The Wisdom of Eleanor Roosevelt
Let us explore some ways of sorting large data sets.
By large, I don’t mean typical “big-data” sizes – which might consist of billions of rows. Such data sets fall into the realm of “big data” which we are not exploring today. Instead I am talking of sorting a rather large CSV file – maybe a couple of million rows.
Continue reading “Sorting a Large CSV File”
Create an Excel Pivot table from Java using Apache POI.
“A foolish faith in authority is the worst enemy of truth.”
― Albert Einstein
A Pivot Table is a tool used in Excel for summarizing data. It helps group data using user-selected criteria and compute group summaries using functions such as total, average, count, etc.
Continue reading “Excel Pivot Table using Apache POI”