Learn how to perform SQL-like grouping and summarizing calculations on Java Collections (List, Map, etc).
Have you wanted to perform SQL-like operations on data in a List or a Map? Maybe computing a sum or average? Or perhaps performing an aggregate operation such as summing a group? Well, with Java 8 streams operations, you are covered for some of these.
A previous article covered sums and averages on the whole data set. In this article, we show how to use Collectors.groupingBy() to perform SQL-like grouping on tabular data.
Continue reading “Java Streams groupingBy Examples”
Use Java 8 Streams and Collectors to slice and dice lists including computing sums, averages, partitioning and more.
Java 8 provides the new Streams facility which makes many Collection operations easy. Streaming items from a collector and filtering the data are trivial. As well as are sorting, searching and computing aggregates. That is, if you are familiar with the many Collectors functions available. We present some of these functions here.
Continue reading “Using Java Collectors”
Export data from Excel spreadsheet to CSV using Java. Properly handles exporting Unicode data in the spreadsheet.
Let us look into how to convert Excel to CSV.
CSV stands for Comma-Separated-Values and is a very common format used for exchanging data between diverse applications. While the Excel Spreadsheet file format is complex (since it has to accommodate a lot more!), CSV is a simpler format representing just tabular data.
Continue reading “Convert Excel to CSV (UTF-8)”
When reading and writing to a child process, it is necessary to execute the read and write blocks in separate threads to avoid deadlock.
In the previous part of this Java Process Guide, we looked at how to read from and write to a child process. While executing the read and write blocks in a single thread works for simple cases, we should run these in separate threads to avoid deadlocks.
Continue reading “Java Process Example Part 2”
Startup a native process from Java using Runtime. Read the output from the process and write some data to it. After you are done, terminate the process.
Have you ever run into a situation where you need to execute an OS command from inside java and read its output? You can use the Process class to do so, but there are some caveats to consider.
Continue reading “Java Process Example”
SQL Server versions and support end dates.
SQL Server Versions
The following table shows the version numbers of SQL Server since it was released for Windows platforms in 1993.
Continue reading “SQL Server Versions”
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
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”
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
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”
Search and sort a HashMap by key as well as by value.
“What you stay focused on will grow.”
― Roy T. Bennett
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”
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.
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”