Common-collections
来源:互联网 发布:怎么制作京东秒杀软件 编辑:程序博客网 时间:2024/06/15 17:37
package cn.toltech.cn.toltech.comm.collections;import cn.toltech.cn.toltech.comm.beanutils.po.T_DynaBean;import org.apache.commons.beanutils.BeanPropertyValueChangeClosure;import org.apache.commons.collections.*;import org.apache.commons.collections.bag.HashBag;import org.apache.commons.collections.bidimap.TreeBidiMap;import org.apache.commons.collections.map.HashedMap;import org.apache.commons.collections.map.LinkedMap;import java.util.ArrayList;import java.util.List;/** * Created by sz0816 on 14-10-17. */public class TestCollections { public static void main(String []args){ TestCollections testCollections = new TestCollections();// testCollections.testIterableMap();// testCollections.testOrderedMap();// testCollections.testBidiMap();// testCollections.testBag(); testCollections.testCollectionUtilsAllDo(); } /*** * 使用IterableMap可以进行迭代Map集合 */ public void testIterableMap(){ IterableMap map = new HashedMap(); map.put("1","小叶子"); map.put("2","小名"); MapIterator mapIterator = map.mapIterator(); while (mapIterator.hasNext()){ System.out.println(mapIterator.next()); System.out.println(mapIterator.getKey()+"=="+mapIterator.getValue()); } } /*** * 进行排好顺序的Map集合 */ public void testOrderedMap(){ OrderedMap map = new LinkedMap(); map.put("1","小叶子"); map.put("2","小伙子"); map.put("3","小凳子"); System.out.println(map.nextKey("2")); //获取key为2的上一个key System.out.println(map.previousKey("2")); //获取key为2的下一个key } /**** * 双向链表,可以通过key来获取value,也可以通过value来获取key * 可以将key和value进行交换 */ public void testBidiMap(){ BidiMap bidi = new TreeBidiMap(); bidi.put("SIX", "6"); bidi.get("SIX"); // returns "6" bidi.getKey("6"); // returns "SIX"// bidi.removeValue("6"); // removes the mapping// bidi.remove("SEX"); //删除key为SEX对应的value// System.out.println(bidi.getKey("6"));// System.out.println(bidi.get("SEX")); BidiMap inverse = bidi.inverseBidiMap(); // returns a map with keys and values swapped System.out.println(inverse.get("6")); } /** * 可以进行包内的数据进行相加 */ public void testBag(){ Bag bag = new HashBag(); bag.add("yezi",1); bag.add("yezi",3); System.out.println(bag.getCount("yezi")); System.out.println(bag.remove("yezi",12)); System.out.println(bag.getCount("yezi")); } /*** * 配合Common-BeanUtils使用 */ public void testCollectionUtilsAllDo(){ BeanPropertyValueChangeClosure closure = new BeanPropertyValueChangeClosure("name","111111"); List<T_DynaBean> list = new ArrayList<T_DynaBean>(); T_DynaBean bean = null; for(int i=0;i<10;i++){ bean = new T_DynaBean(); bean.setName("-"+i); bean.setId(i); list.add(bean); } CollectionUtils.forAllDo(list, closure); for(int i=0;i<list.size();i++){ bean = list.get(i); System.out.println(bean.getName()); } }}
0 0
- Common-collections
- 倚天剑:apache-common-collections
- Java Collection Framework扩展Apache Common Collections介绍
- Collections
- Collections
- Collections
- collections
- Collections
- COLLECTIONS
- Collections
- Collections
- collections
- Collections
- Collections
- collections
- Collections
- Collections
- collections
- javascript追加html实现类似jQuery中append方法
- Linux RTC驱动分析(一)----pcf8563驱动和class.c
- OGNL表达式
- scrapy setting.py文件
- Intent中的FLAG
- Common-collections
- xslt中的apply-template和call-template的区别
- 还好我们有朋友-蝌蚪
- 08.栈(二)栈的应用
- CF22B 最大子矩阵问题简单版
- android中MotionEvent.ACTION_CANCEL事件如何被触发?
- jq弹出层与自动隐藏,屏幕居中显示,弹出层的移动原理
- c++ 正则表达式
- goto语句(转)