Java Tips: Initializing Collection

Especially in unit test, it is common case that we have to initialize an array or a collection. Well, for array, it’s OK… A simple code that we know can solve the problem: But how about Collection? Normal way to initialize collection is something like this (which pretty ugly): I hardly find an elegant solution …

Computing Map on Google Collections

Google always makes interesting projects. My toy nowadays is Google Collections. I don’t think I need to reintroduce it as it has been nicely covered on several blog posts: Introduction to Google Collections A series from CodeMunchies Beautiful code with Google Collections, Guava, and Static Imports Diving Into the Google Guava Library Functional Java Filtering …

Java Tips: Optimizing your Map loop

Quite often, a program needs to go through all elements of a Map. Unfortunately, like a Set, a Map doesn’t have index in the data structure so you can’t just get a key of certain index or a value of certain index. The most common practice used to iterate all elements in a Map is …