Home » Tag Archives: Collections

Tag Archives: Collections

Consuming java.util.concurrent.BlockingQueue as rx.Observable

java-logo

Classical producer-consumer pattern is relatively simple in Java since we have java.util.concurrent.BlockingQueue. To avoid busy waiting and error-prone manual locking we simply take advantage of put() and take(). They both block if queue is full or empty respectively. All we need is a bunch of threads sharing reference to the same queue: some producing and others consuming. And of course ...

Read More »

Transforming Collections

java-logo

Did you ever want to substitute the equals and hashCode methods a HashSet or HashMap uses? Or have a List of some element type masquerade as a List of a related type? Transforming collections make that possible and this post will show how. Overview Transforming collections are a feature of LibFX 0.3.0, which will be released any day now. This ...

Read More »

How to Use Java 8 Streams to Swiftly Replace Elements in a List

java-logo

Imagine you have a list of items: List<String> books = Arrays.asList( "The Holy Cow: The Bovine Testament", "True Hip Hop", "Truth and Existence", "The Big Book of Green Design" ); (Don’t judge me. Books from this random book generator) Now you’d like to create a new list where the third item only is replaced by some new value: List<String> books ...

Read More »

Transforming Collections with Decorators

java-design-patterns-logo_scaled

The Decorator Pattern Ever since first learning the programming design patterns, the decorator pattern has been my favorite. It seemed such a novel idea to me, and so much more interesting than the others. Don’t get me wrong, most of the others blew my mind too, but none so much as the decorator pattern. To this day, it’s still one ...

Read More »

Stream-Powered Collections Functionality in JDK 8

java-logo

This post presents application of JDK 8 – introduced Streams with Collections to more concisely accomplish commonly desired Collections-related functionality. Along the way, several key aspects of using Java Streams will be demonstrated and briefly explained. Note that although JDK 8 Streams provide potential performance benefits via parallelization support, that is not the focus of this post. The Sample Collection ...

Read More »

How to use CopyOnWriteArraySet in Java with Example

java-logo

CopyOnWriteArraySet is little brother of CopyOnWriteArrayList class. These are special purpose collection classes which was added on JDK 1.5, along with their most popular cousin ConcurrentHashMap. They are part of concurrent collection framework and reside in java.util.concurrent package. CopyOnWriteArraySet is best suited as read-only collection whose size is small enough to copy if some mutative operation happens, for example you ...

Read More »

Code4ReferenceList Recently Used(LRU) implementation using LinkedHashMap

java-logo

Recently I stumbled on one of the Java interview questions: “Implement List-Recently-Used (LRU) Cache using Java collection class?” If you have worked on a similar problem before, then it is really easy for you. Otherwise you start thinking about the best collection class to implement LRU cache. Most of the people fail to recognize that LinkedHashMap provides the support and ...

Read More »

HashMap performance improvements in Java 8

java-logo

HashMap<K, V> is fast, versatile and ubiquitous data structure in every Java program. First some basics. As you probably know, it uses hashCode() and equals() method of keys to split values between buckets. The number of buckets (bins) should be slightly higher than the number of entries in a map, so that each bucket holds only few (preferably one) value. ...

Read More »

Oracle Drops Collection Literals in JDK 8

java-logo

In a posting on the OpenJDK JEP 186 Oracle’s Brian Goetz informs that Oracle will not be pursuing collection literals as a language feature in JDK8. A collection literal is a syntactic expression form that evaluates to an aggregate type as an array, List or Map. Project Coin proposed collection literals, which also complements the library additions in Java SE8. ...

Read More »
Want to take your Java Skills to the next level?
Grab our programming books for FREE!
  • Save time by leveraging our field-tested solutions to common problems.
  • The books cover a wide range of topics, from JPA and JUnit, to JMeter and Android.
  • Each book comes as a standalone guide (with source code provided), so that you use it as reference.
Last Step ...

Where should we send the free eBooks?

Good Work!
To download the books, please verify your email address by following the instructions found on the email we just sent you.