Java concurrency: Understanding CopyOnWriteArrayList and CopyOnWriteArraySet

Java has a huge amount of useful collections and several are made specifically for use in concurrent code like the ConcurrentHashMap. Two sometimes very useful classes are the CopyOnWriteArrayList and CopyOnWriteArraySet. They implement the java.util.List and the java.util.Set interface respectively. Let’s focus on the CopyOnWriteArrayList to understand what it is all about. Contrary to the […]

Understanding java.util.concurrent.CompletionService

The java.util.concurrent.CompletionService is a useful interface in the JDK standard libraries but few developers know it. One could live without it as you can of course program this functionality with the other interfaces and classes within java.util.concurrent but it is convenient to have a solution that is already available and less error prone then doing […]

A little functional Java – the map function

Functional programming is getting a lot of interested nowadays. Languages like Clojure or Scala are on the rise and even languages like Haskell which where formerly considered to be mostly academic are getting more and more popular. And more and more Java programmers are thinking about functional programming. Java 8 will get lambda expressions which […]

BitSets in Scala are much more fun than in Java

Recently I played with BitSets in Java because I needed an efficient way to store huge amounts of long values. For Java there is the java.util.BitSet class. It is a very efficient implementation when you only need to store bit values. Here is a trivial example on how to use it:

It is very […]

Using DirectoryStreams in Java 7

Java 7 comes with lot’s of new stuff for IO. The new interfaces and classes added to the java.nio package contain lot’s of useful functionality for working with files and other things like asynchronous IO. Here I want to show you a little bit about the interface DirectoryStream which is very useful when you want […]