`

Guava Collections - Multimap Interface

 
阅读更多

Multimap Interface

Multimap interface extends Map so that its keys can be mapped to multiple values at a time.

package org.fool.guava.collections;

import java.util.Collection;
import java.util.Map;
import java.util.Set;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;

public class MultimapTest {
	public static void main(String[] args) {
		Multimap<String, String> multimap = ArrayListMultimap.create();

		multimap.put("lower", "a");
		multimap.put("lower", "b");
		multimap.put("lower", "c");
		multimap.put("lower", "d");
		multimap.put("lower", "e");

		multimap.put("upper", "A");
		multimap.put("upper", "B");
		multimap.put("upper", "C");
		multimap.put("upper", "D");

		Collection<String> lowerCollection = multimap.get("lower");

		System.out.println("Initial lower case list");
		System.out.println(lowerCollection.toString());
		lowerCollection.add("f");
		System.out.println("Modified lower case list");
		System.out.println(lowerCollection.toString());

		Collection<String> upperCollection = multimap.get("upper");
		System.out.println("Initial upper case list");
		System.out.println(upperCollection.toString());
		upperCollection.remove("D");
		System.out.println("Modified upper case list");
		System.out.println(upperCollection.toString());

		Map<String, Collection<String>> map = multimap.asMap();
		System.out.println("Multimap as a map");
		map.forEach((key, value) -> System.out.println(key + ":" + value));
		
		System.out.println("Keys of Multimap");
		Set<String> keys = multimap.keySet();
		keys.forEach(key -> System.out.println(key));
		
		System.out.println("Values of Multimap");
		Collection<String> values = multimap.values();
		System.out.println(values);
	}
}

 output

Initial lower case list
[a, b, c, d, e]
Modified lower case list
[a, b, c, d, e, f]
Initial upper case list
[A, B, C, D]
Modified upper case list
[A, B, C]
Multimap as a map
lower:[a, b, c, d, e, f]
upper:[A, B, C]
Keys of Multimap
lower
upper
Values of Multimap
[a, b, c, d, e, f, A, B, C]

 

分享到:
评论

相关推荐

    guava-collections-r03.jar

    guava类似Apache Commons工具集包含了若干被Google的 Java项目广泛依赖 的核心库

    guava-30.0-jre-API文档-中文版.zip

    赠送jar包:guava-30.0-jre.jar; 赠送原API文档:guava-30.0-jre-javadoc.jar; 赠送源代码:guava-30.0-jre-sources.jar; 赠送Maven依赖信息文件:guava-30.0-jre.pom; 包含翻译后的API文档:guava-30.0-jre-...

    guava-27.0.1-jre-API文档-中文版.zip

    赠送jar包:guava-27.0.1-jre.jar; 赠送原API文档:guava-27.0.1-jre-javadoc.jar; 赠送源代码:guava-27.0.1-jre-sources.jar; 赠送Maven依赖信息文件:guava-27.0.1-jre.pom; 包含翻译后的API文档:guava-...

    guava-25.0-jre-API文档-中文版.zip

    赠送jar包:guava-25.0-jre.jar; 赠送原API文档:guava-25.0-jre-javadoc.jar; 赠送源代码:guava-25.0-jre-sources.jar; 赠送Maven依赖信息文件:guava-25.0-jre.pom; 包含翻译后的API文档:guava-25.0-jre-...

    Google-Guava-Collections-使用介绍

    ### Google Guava Collections 使用介绍 #### 一、概述 Google Guava Collections 是 Java Collections Framework 的一个强大且实用的非官方扩展 API。它由 Google 工程师 Kevin Bourrillion 和 Jared Levy 在著名...

    guava-20.0-API文档-中文版.zip

    赠送jar包:guava-20.0.jar; 赠送原API文档:guava-20.0-javadoc.jar; 赠送源代码:guava-20.0-sources.jar; 赠送Maven依赖信息文件:guava-20.0.pom; 包含翻译后的API文档:guava-20.0-javadoc-API文档-中文...

    guava-27.0-jre.jar

    guava-27.0-jre.jar

    guava-11.0.2-API文档-中文版.zip

    赠送jar包:guava-11.0.2.jar; 赠送原API文档:guava-11.0.2-javadoc.jar; 赠送源代码:guava-11.0.2-sources.jar; 赠送Maven依赖信息文件:guava-11.0.2.pom; 包含翻译后的API文档:guava-11.0.2-javadoc-API...

    guava-29.0-jre-API文档-中英对照版.zip

    赠送jar包:guava-29.0-jre.jar; 赠送原API文档:guava-29.0-jre-javadoc.jar; 赠送源代码:guava-29.0-jre-sources.jar; 赠送Maven依赖信息文件:guava-29.0-jre.pom; 包含翻译后的API文档:guava-29.0-jre-...

    guava-18.0(guava-18.0.jar和guava-18.0-sources.jar)

    这个压缩包包含的是Guava库的18.0版本,分为两个部分:`guava-18.0.jar`和`guava-18.0-sources.jar`。 `guava-18.0.jar`是Guava库的编译后的二进制版本,包含了所有Guava类和方法的字节码,开发者可以直接在项目中...

    guava-28.2-jre-API文档-中文版.zip

    赠送jar包:guava-28.2-jre.jar; 赠送原API文档:guava-28.2-jre-javadoc.jar; 赠送源代码:guava-28.2-jre-sources.jar; 赠送Maven依赖信息文件:guava-28.2-jre.pom; 包含翻译后的API文档:guava-28.2-jre-...

    guava-27.1-jre.jar

    guava-27.1-jre

    guava-16.0.1-API文档-中文版.zip

    赠送jar包:guava-16.0.1.jar; 赠送原API文档:guava-16.0.1-javadoc.jar; 赠送源代码:guava-16.0.1-sources.jar; 赠送Maven依赖信息文件:guava-16.0.1.pom; 包含翻译后的API文档:guava-16.0.1-javadoc-API...

    guava-26.0-jre.zip

    1. **集合框架增强**:Guava提供了许多强大的集合类,如Multiset(多集)、Multimap(多映射)、ImmutableList、ImmutableSet和ImmutableMap等。这些集合在可变性、并发性和性能方面都进行了优化,能够更好地满足...

    最新版 guava-30.1-jre.jar

    最新版 guava-30.1-jre.jar

    guava-27.0.1-jre-API文档-中英对照版.zip

    赠送jar包:guava-27.0.1-jre.jar; 赠送原API文档:guava-27.0.1-jre-javadoc.jar; 赠送源代码:guava-27.0.1-jre-sources.jar; 赠送Maven依赖信息文件:guava-27.0.1-jre.pom; 包含翻译后的API文档:guava-...

    guava-20.0-API文档-中英对照版.zip

    赠送jar包:guava-20.0.jar; 赠送原API文档:guava-20.0-javadoc.jar; 赠送源代码:guava-20.0-sources.jar; 赠送Maven依赖信息文件:guava-20.0.pom; 包含翻译后的API文档:guava-20.0-javadoc-API文档-中文...

    google-collections-1.0-rc2.jar

    google-collections-1.0-rc2.jar 的jar包,放心使用。

    guava-28.2-android.jar

    guava-28.2-android.jar

    guava-18.0-API文档-中文版.zip

    赠送jar包:guava-18.0.jar; 赠送原API文档:guava-18.0-javadoc.jar; 赠送源代码:guava-18.0-sources.jar; 包含翻译后的API文档:guava-18.0-javadoc-API文档-中文(简体)版.zip 对应Maven信息:groupId:...

Global site tag (gtag.js) - Google Analytics