Search code examples
javaguava

How to create a synchronized version of Google Guava's TreeMultimap


Does anyone know how to create a thread safe instance of TreeMultimap with TreeMultimap.create()?


Solution

  • The Guava Multimaps class contains static methods for creating and decorating Multimaps, similar to what the Collections class in java.util provides for Collections and Maps.

    In your case, you should use:

    Multimaps.synchronizedSortedSetMultimap(TreeMultimap.create())