关注google的guava工具包
来源:互联网 发布:怪物猎人捏脸数据库 编辑:程序博客网 时间:2024/05/17 20:15
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的查询:
再来点例子,加深了解:
更详细的看:
http://docs.guava-libraries.googlecode.com/git-history/release09/javadoc/com/google/common/collect/Multimap.html
留意到其中的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
0 0
- 关注google的guava工具包
- 关注google的guava工具包
- google guava工具包 checkNotNull的作用
- google 的guava学习
- 【Sets】使用Google Guava工程中Sets工具包,实现集合的并集/交集/补集/差集
- Google的Guava cache 应用
- Google Guava的splitter用法
- google guava的Preconditions使用
- Guava扩展工具包
- Google guava
- Google Guava
- google guava
- google guava
- Google Guava
- [Google Guava] 排序: Guava强大的”流畅风格比较器”
- google工具包
- google guava bloom filter包的坑
- Google的Java常用类库 Guava
- 分类续
- 新浪微博架构和FEED架构分析--人人架构
- Java中使用二分法排序
- MapReduce,DataJoin,多表连接查询
- ActiveX控件开发
- 关注google的guava工具包
- iOS应用中通过设置VOIP模式实现休眠状态下socket的长连接
- javascript性能提升——访问集合元素时使用局部变量
- 慢下来的时光
- 漫的孩子也给他的生活增
- ios 笔记
- 整理:数据结构面试大全
- 2014年2月28日 extendmin()和extendmax()函数实战
- 程序员的奋斗史(三十二)——人在囧途之应聘篇(二)