`

关注google的guava工具包

阅读更多
google的guava工具包的确很多好东西,包括之前的字符串处理工具类的,还有大量的collection相关的,项目地址在:http://code.google.com/p/guava-libraries/
留意到其中的collection相关类中的map,简单介绍如下,更多的请大家补充挖掘或者
看原来的文档:



    guava提供的是多值map!,就是说,一个key,可以对应多个value了,比如一个人会有多个联系号码等,可以表达为:
    multimap<String,String> phonebook=ArrayListMultmap.create();
    phonebook.put("a","43434");
    phonebook.put("b","3434434");
  system.out.println(phonebook,get("a"));


  还有map的查询:
  
Map<String, Integer> user = new HashMap<String, Integer>();
		user.put("张三", 20);
		user.put("李四", 22);
		user.put("王五", 25);
		// 所有年龄大于20岁的人员
		Map<String, Integer> filtedMap = Maps.filterValues(user,
				new Predicate<Integer>() {
					public boolean apply(Integer value) {
						return value > 20;
					}
				});
		System.out.println(filtedMap);




   再来点例子,加深了解:

  

public class MutliMapTest {
    public static void main(String... args) {
  Multimap<String, String> myMultimap = ArrayListMultimap.create();

  // Adding some key/value
  myMultimap.put('Fruits', 'Bannana');
  myMultimap.put('Fruits', 'Apple');
  myMultimap.put('Fruits', 'Pear');
  myMultimap.put('Vegetables', 'Carrot');

  // Getting the size
  int size = myMultimap.size();
  System.out.println(size);  // 4

 
  Collection<string> fruits = myMultimap.get('Fruits');
  System.out.println(fruits); // [Bannana, Apple, Pear]

  Collection<string> vegetables = myMultimap.get('Vegetables');
  System.out.println(vegetables); // [Carrot]

  // 循环输出
  for(String value : myMultimap.values()) {
   System.out.println(value);
  }

  // 移走某个值
  myMultimap.remove('Fruits','Pear');
  System.out.println(myMultimap.get('Fruits')); // [Bannana, Pear]

  //移走某个KEY的所有对应value
  myMultimap.removeAll('Fruits');
  System.out.println(myMultimap.get('Fruits')); // [] (Empty Collection!)
 }
}



  更详细的看:
http://docs.guava-libraries.googlecode.com/git-history/release09/javadoc/com/google/common/collect/Multimap.html
11
6
分享到:
评论
5 楼 ron.luo 2014-08-28  
牛逼Class.
4 楼 alyouge 2012-12-13  
果然是个好东西
3 楼 hahalq 2012-12-13  
恩。。。不错的工具
2 楼 jackyrong 2012-12-12  
原来这样,感谢
1 楼 kidneyball 2012-12-12  
guava 12的ListMultiMap序列化时会抛异常,不能放在EJB或者Session(如果需要Session复制的话)里。guava 13还没有机会测试。

相关推荐

    Google的Guava工具包

    Guava 是一个 Google 的基于java1.6的类库集合的扩展项目,包括 collections, caching, primitives support, concurrency libraries, common annotations, string processing, I/O, 等等. 这些高质量的 API 可以使你...

    guava-use:使用谷歌guava工具包

    花式学习 番石榴使用 java8-lambda Java反射 Java注释

    guava14.0.1jar包及API文档

    Guava工程包含了若干被Google的 Java项目广泛依赖 的核心库,例如:集合 [collections] 、缓存 [caching] 、原生类型支持 [primitives support] 、并发库 [concurrency libraries] 、通用注解 [common annotations] ...

    Guava的Jar包(guava-26.0-jre.jar)

    Guava是Google公司开发的一款适用于Java的工具类集合。

    guava-25.1-jre.jar

    google的guava工具包很实用,包括之前的字符串处理工具类的,还有大量的collection相关的

    Google开源Guava包让使用Java语言变得更舒适

    Guava工程包含了若干被Google的 Java项目广泛依赖 的核心库,例如:集合 [collections] 、缓存 [caching] 、原生类型支持 [primitives support] 、并发库 [concurrency libraries] 、通用注解 [common annotations] ...

    guava、javax.inject-1、jsr305-3.0.1 jar包

    google guava工具包 其中包括javax.inject jsr305-3.0.1和所有的源码。不然会报错。

    Guava 16.0 API (CHM格式)

    缓存工具包,非常简单易用且功能强大的JVM内缓存。  com.google.common.collect:带泛型的集合接口扩展和实现,以及工具类,这里你会发现很多好玩的集合。  com.google.common.eventbus:发布订阅风格的事件总线。...

    java集合分组(Guava)

    因工作的需要,利用Guave对集合进行分组。这是个最简单的例子,希望对大家有用。

    guava16.0 chm文档

    缓存工具包,非常简单易用且功能强大的JVM内缓存。  com.google.common.collect:带泛型的集合接口扩展和实现,以及工具类,这里你会发现很多好玩的集合。  com.google.common.eventbus:发布订阅风格的事件总线...

    Guava-17.0.jar

    google官网guava最新jar包,好用

    google-guava

    所有这些工具每天都在被Google的工程师应用在产品服务中。 查阅Javadoc并不一定是学习这些库最有效的方式。在此,我们希望通过此文档为Guava中最流行和最强大的功能,提供更具可读性和解释性的说明。

    guava-18.0.jar包官方免费版

    guava-18.0.jar包是一款免费的jar包,Guava中文是石榴的意思,该项目是Google的一个开源项目,包含许多 Google 核心的 Java 常用库,给大家提供guava18.0.jar,需要此款工具的朋友们欢迎前来下载使用。 基本简介 ...

    guava-collections-r03.jar

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

    guava-14.0.1.jar

    Guava工程包含了若干被Google的 Java项目广泛依赖 的核心库,例如:集合 [collections] 、缓存 [caching] 、原生类型支持 [primitives support] 、并发库 [concurrency libraries] 、通用注解 [common annotations] ...

    GuavaGoogle的Java核心库

    Guava项目包含了很多Java项目开发中依赖的Google核心库:集合、缓存、基础类型支持、并发库、通用注解、字符串处理、I/O等等。

    Guava-Event-Bus:Guava的EventBus源码学习

    EventBus是google的一个Java工具包其中的一个工具类,类似的有多个版本其中包括移植到Android端的 和改良的,功能基本都是一样的。此处主要是对Guava版的EventBus分析,关于。 ###2. 功能简介 ####2.1 EventBus介绍 ...

    Google发布的Java工具库

    Guava 中文是石榴的意思,该项目是 Google 的一个开源项目,包含许多 Google 核心的 Java 常用库。 目前主要包含: com.google.common.annotations com.google.common.base com.google.common.collect ...

    notes-learning-guava:guava学习笔记

    引言Guava工程包含了若干被Google的Java项目广泛依赖的核心库,例如:集合[collections] 、缓存[caching] 、原生类型支持[primitives support] 、并发库[concurrency libraries] 、通用注解[common annotations] 、...

Global site tag (gtag.js) - Google Analytics