Tag: Guava
-
Guava: Elegant Collection Ordering
PROBLEM Java provides a built-in API to sort a list, but it is flat out ugly and prone to error especially when dealing with Comparator. Here’s an example:- Number of puppies killed = 3 … from the if-else statement. SOLUTION A better way to do this is to use Ordering from Guava:- </request,> In this… Read More…
-
Java: Performing 2-Key Lookup using HashBasedTable
PROBLEM HashMap is great to perform a simple lookup, for example:- However, what if we need 2 keys to lookup a value? For example, we need “key1” + “key2” in order to lookup “mike”. SOLUTION 1: Create combo key You can combine the keys to create a unique key:- Assuming if the keys are just… Read More…