Java Streams: Write Functional Collection code in Java
I started my career as a Java developer back in 2011. I developed most of my code in the 1.7 version of Java. Around 2014, I switched to full-time Scala and have not programmed in Java ever since.
Java used to be a slow-moving language that had started lagging behind the other languages. Scala kind of filled that gap of modern language on a JVM. But in the last few years, it has changed. There is a new version of Java every 6 months and it has been getting new features at a very rapid pace. So I thought it will be interesting to go back to Java now and see how it has evolved compared to Java 7.
So in this series of posts, I will be talking about new features of Java from a Scala developer’s point of view. I will be using?Java 17, the latest LTS version, for these examples.
This is the fifth post in the series where I will be discussing the Java streams. You can find all the posts in the series?here.
Java Collections and Mutability
Java collections are one of the earliest APIs that was added to Java language. Java built-in collections made the language feature-rich and productive compared to other languages of the time like C/C++. They have served language well in the last 2 decades.
One of the cornerstone idea of the collections is that they are mutable by default. It’s great for memory management and object-oriented programming but it’s not great if you want to express the collections operations in a functional programming way.