第五十七篇:commons-collections使用介绍之Bag
来源:互联网 发布:2017最新车主一手数据 编辑:程序博客网 时间:2024/06/04 19:57
在commons-collections中为我们提供了一些关于集合的实现,今天为大家介绍一下Bag
相关类的用法。
概述
Bag
继承自Collection
接口,定义了一个集合,该集合会记录对象在集合中出现的次数。
假设你有一个包,包含{a, a, b, c}。调用getCount(a)方法将返回2,调用uniqueset()方法将返回{a, b, c}。
API
方法摘要
HashBag
HashBag
使用HashMap
作为数据存储,是一个标准的Bag
实现。
使用示例:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
运行结果: 包中元素为:
s1
s1
s2
s2
s2
包中元素个数为:5
包中entity1个数为:2
去重后个数为:2
TreeBag
TreeBag
使用TreeMap
作为数据存储,用法与HashBag
类似,只是TreeBag
会使用自然顺序对元素进行排序。
使用示例:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
运行结果:
包中元素为:
s1
s2
s3
包中元素个数为:3
包中entity1个数为:1
去重后个数为:3
关于Bag的更多内容,可以去官网查看相关的帮助文档。
阅读全文
0 0
- 第五十七篇:commons-collections使用介绍之Bag
- commons-collections使用介绍之Bag
- commons-collections使用介绍之Bag HashBag
- 第五十八篇:commons-collections使用介绍之List
- 第五十九篇:commons-collections使用介绍之Map
- Apache commons 之 Collections :Bag
- commons-collections使用介绍之List
- commons-collections使用介绍之Map
- org.apache.commons.collections学习笔记【一】之Bag
- 第五十六篇: commons-dbutils使用介绍
- Apache Commons Collections组件介绍使用
- Apache commons 之 Collections :总览
- Apache commons 之 Collections:Buffer
- Apache commons 之 Collections :Map
- Apache commons 之 Collections :LazyMap
- Apache commons 之 Collections :Comparator
- Apache commons 之 Collections :Predicate
- Apache commons 之 Collections :Iterator
- Spring Boot的listener简单使用
- Pi衰减
- Shiro简介
- android面试题——内存管理(0三)
- aliyun阿里云Maven仓库地址——加速你的maven构建
- 第五十七篇:commons-collections使用介绍之Bag
- 虚拟机ping不通主机,无法上网问题
- 汇哲科技- 8月31日国盟CISA每日一题
- 记一次页面失效,你正在尝试访问一个无效页面的错误
- 加载数据到ListView
- 微信网页授权登陆如何实现回调多个域名?
- 汇哲科技- 8月31日国盟CISSP每日一题
- JavaScriptSerializer序列化和反序列化JSON:使用自定义JavaScriptConverter JSON的序列化和反序列化已经成为Web开发必不可少的知识。现在常用的有Syste
- map和reduce数量控制