设为首页 加入收藏

TOP

Apache Commons Collections基本操作(Predicate、Transformat、Closure等)(四)
2015-11-21 01:01:37 来源: 作者: 【 】 浏览:14
Tags:Apache Commons Collections 基本操作 Predicate Transformat Closure
tor it = bag.iterator(); while(it.hasNext()) { System.out.print(it.next()+" "); } System.out.println(); } //有序的包 public static void treeBag() { System.out.println("=====有序的包========"); Bag bag = new TreeBag<>(); bag.add("a"); bag.add("a",5); bag.remove("a",2); bag.add("b"); bag.add("c"); Iterator it = bag.iterator(); while(it.hasNext()) { System.out.print(it.next()+" "); } System.out.println(); } public static void wordcount(){ String str = "this is a cat and that is a micewhere is the food"; String[] strArray = str.split(" "); Bag bag = new TreeBag<>(); for(String temp:strArray) { bag.add(temp); } System.out.println("=====统计次数========"); Set keys = bag.uniqueSet(); for(String letter:keys) { System.out.println(letter+"-->"+bag.getCount(letter)); } } }

运行结果:

=====无序的包========
b c a a a a 
=====有序的包========
a a a a b c 
=====统计次数========
a-->2
and-->1
cat-->1
food-->1
is-->3
micewhere-->1
that-->1
the-->1
this-->1
首页 上一页 1 2 3 4 5 6 7 下一页 尾页 4/7/7
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C++ string 类 学习笔记 下一篇C++――2828: 素数判断

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: