Home » Tag Archives: Collections (page 3)

Tag Archives: Collections

Selecting your Collections library

java-logo

Is this really something you should bother? Is there something fundamentally wrong with java.util.ArrayList and java.util.HashMap? For most of the source code out there the answer is – no; those implementations are perfectly OK. But as always, the devil is in the details. And there exist situations when either the feature set built into the Collections API is not sufficient ...

Read More »

Type-safe Empty Collections in Java

java-logo

I have blogged before on the utility of the Java Collections class and have specifically blogged on Using Collections Methods emptyList(), emptyMap(), and emptySet(). In this post, I look at the sometimes subtle but significant differences between using the relevant fields of the Collections class for accessing an empty collection versus using the relevant methods of the Collections class for ...

Read More »

Java: Choosing the right Collection

java-logo

Here is a quick guide for selecting the proper implementation of a Set , List , or Map in your application. The best general purpose or ‘primary’ implementations are likely ArrayList, LinkedHashMap, and LinkedHashSet. Their overall performance is better, and you should use them unless you need a special feature provided by another implementation. That special feature is usually ordering or sorting. Here, ‘ordering’ refers to ...

Read More »

Java 7: HashMap vs ConcurrentHashMap

java-logo

As you may have seen from my past performance related articles and HashMap case studies, Java thread safety problems can bring down your Java EE application and the Java EE container fairly easily. One of most common problems I have observed when troubleshooting Java EE performance problems is infinite looping triggered from the non-thread safe HashMap get() and put() operations. ...

Read More »

Five useful ways to sorting in java

java-logo

A rapid overview of java sorting :                     normal sort of list : private static List VEGETABLES = Arrays.asList("apple", "cocumbers", "blackberry"); Collections.sort(VEGETABLES); output: apple, blackberry, cocumbers Reverse sorting: private static List VEGETABLES = Arrays.asList("apple", "cocumbers", "blackberry"); Collections.sort(VEGETABLES, Collections.reverseOrder()); output: cocumbers, blackberry, apple with custom comparator: private class StringComparator implements Comparator { ...

Read More »

Array, list, set, map, tuple, record literals in Java

java-logo

Occasionally, when I’m thrilled by the power and expressiveness of JavaScript, I find myself missing one or two features in the Java world. Apart from lambda expressions / closures or whatever you want to call “anonymous functions”, it’s the use of advanced literals for common data types, such as arrays, lists, sets, maps, etc. In JavaScript, no one would think ...

Read More »

Common and Unique Elements In Multiple Collections

apache-commons-logo

This week, we’ll take a break from higher level problems and technology posts to deal with just a little code problem that a lot of us have probably faced. It’s nothing fancy or too hard, but it may save one of you 15 minutes someday, and occasionally it’s nice to get back to basics. So let’s get down to it. ...

Read More »

Avoid Lazy JPA Collections

jboss-hibernate-logo

Hibernate (and actually JPA) has collection mappings: @OneToMany, @ManyToMany, @ElementCollection. All of these are by default lazy. This means the collections are specific implementations of the List or Set interface that hold a reference to the persistent session and the values are loaded from the database only if the collection is accessed. That saves unnecessary database queries if you only ...

Read More »

Java Best Practices – Queue battle and the Linked ConcurrentHashMap

java-logo

Continuing our series of articles concerning proposed practices while working with the Java programming language, we are going to perform a performance comparison between four popular Queue implementation classes with relevant semantics. To make things more realistic we are going to test against a multi–threading environment so as to discuss and demonstrate how to utilize ArrayBlockingQueue, ConcurrentLinkedQueue, LinkedBlockingQueue and/or LinkedList ...

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.