Dictionaries hold key-value pairs where the key is the index. An inverted dictionary is one where the values become the keys and the keys becomes the values. Dictionaries are frequently used to support many NLP tasks. For example, in the previous recipe, Summarizing text in a document, the LinkedHashMap class was used internally to maintain the word frequency with respect to the number of occurrences for text.
In this recipe, we will explore how dictionaries and inverted dictionaries are handled in Java. We will use the Java core SDK and the Guava (Google core libraries for Java and API for our libraries). The Guava website is found at https://github.com/google/guava.
Problems can arise when the values are not unique. We will use the Java 8 Streams to address these issues.