import com.google.common.collect.ArrayListMultimap;
public class TestGuavaMultiMaps {
public static void main(String[] args) {
ArrayListMultimap<String, String> multimap = ArrayListMultimap.create();
multimap.put("A", "1");
multimap.put("B", "1");
multimap.put("C", "1");
multimap.put("A", "2");
multimap.put("B", "2");
multimap.put("C", "2");
multimap.put("A", "3");
multimap.put("B", "3");
System.out.println(multimap); // {A=[1, 2, 3], B=[1, 2, 3], C=[1, 2]}
multimap.asMap().remove("A");
System.out.println(multimap); // {B=[1, 2, 3], C=[1, 2]}
multimap.get("B").remove("1");
System.out.println(multimap); // {B=[2, 3], C=[1, 2]}
multimap.get("B").remove("2");
multimap.get("B").remove("3");
System.out.println(multimap); // {C=[1, 2]}
}
}
No comments:
Post a Comment