Code:
Multimap<String, String> myMultimap = ArrayListMultimap.create();
myMultimap.put("12345", "qwer");
myMultimap.put("12345", "abcd");
myMultimap.put("12345", "qwer");
System.out.println(myMultimap);
Result:
{12345=[qwer, abcd, qwer]}
Is it possible to eliminate duplicate "qwer" ? Thanks.
Use one of the SetMultimap
implementations, for example HashMultimap
:
SetMultimap<String, String> myMultimap = HashMultimap.create();
myMultimap.put("12345", "qwer");
myMultimap.put("12345", "abcd");
myMultimap.put("12345", "qwer");
System.out.println(myMultimap); // {12345=[abcd, qwer]}