guava库
来源:互联网 发布:淘宝app里面是h5吗 编辑:程序博客网 时间:2024/06/06 03:03
项目中的使用:
1.
Set<Category> categorySet = Sets.newHashSet();2.
List<Integer> categoryIdList = Lists.newArrayList();3.
//传统方法:将productIds分割后转成数组,再遍历数组才能添加到集合当中//这里使用guava提供的方法,直接将其转成集合List<String> productList = Splitter.on(".").splitToList(productIds);//这里也使用guava提供的集合判空if(CollectionUtils.isEmpty(productList)) { return ServerResponse.createByErrorCodeMessage(ResponseCode.ILLEGAL_ARGUMENT.getCode(), ResponseCode.ILLEGAL_ARGUMENT.getDesc());}4.
Map result = Maps.newHashMap();
官方文档:点击打开链接
以前这么用:
Map<String, Map<Long, List<String>>> map = new HashMap<String, Map<Long, List<String>>>();
guava可以简化:
Map<String, Map<Long, List<String>>> map = Maps.newHashMap();
针对不可变集合:
以前这么用:
List<String> list = new ArrayList<String>();list.add("a");list.add("b");
guava简化:
ImmutableList<String> of = ImmutableList.of("a", "b");ImmutableMap<String, String> map = ImmutableMap.of("key1", "value1", "key2", "value2");
基本类型比较:
guava简化:
int compare = Ints.compare(a, b);
set的并集,差集和交集:
SetView union = Sets.union(setA, setB);//并集SetView difference = Sets.difference(setA, setB);//差集SetView intersection = Sets.intersection(setA, setB);//交集
阅读全文
0 0
- Guava库
- guava库
- [Guava源码日报]Guava类库简介
- Guava 库整理
- Google guava 库
- Guava库之collect
- Guava库介绍
- Guava
- Guava
- Guava
- GUAVA
- guava
- guava
- Guava
- Guava
- guava
- Guava
- Guava
- git
- Revit调用winform
- string的正则表达式
- flask1
- mysql innodb 行锁解锁后出现1213 死表现象 Deadlock found when
- guava库
- solr入门
- QT获取字符串的像素的宽与高
- 最新微信小程序,请求第三方api时,无法加载数据报400,解决
- oracle用户权限管理以及profile应用
- PHP工程狮感知的前端工作流程
- JavaScript中对象字面量
- C# mysql 连接查询数据
- mysql(四):mysql的插入,更新和删除操作