Aricles related to

Java



How to generate a stream of random numbers in Java

From time to time you end up with the need of generating some random numbers. In Java, the Random class has been the go-to solution for this type of work. Random serves several helpful methods for creating random ints, doubles and longs. However, if you wanted a sequence of random…


Java 9: Cleaning up your default methods using private interface methods

Java 8 brought huge changes — one of them being the default interface methods. These methods changed interfaces as we knew them — we could now define default implementations in the interface itself. If you use these default methods heavily in your applications, you'll quickly figure out one thing — it doesn't really…


Java 9 - Making the Stream API even better

One of the first things I check out when looking at a new language is if it got a good collection API. I find that a good way of working with collections usually result in cleaner code that is easier to understand and reason about. That's why I was glad…


Java 8: Creating a custom Collector for your Stream

In the previous post we looked at different implementations of the Collector interface. As you saw, there is a wide range of collectors available out of the box. However — sometimes you need something special that you simply have to make yourself. So today we’re going to look at how…


Java 8: Accumulate the elements of a Stream using Collectors

I’ve earlier written about the Stream API and how you can write more declarative code by using it. In this article I want to focus on the different ways of accumulating the elements of a Stream using Collectors. This is made possible by using collect — a method in the…