首页 > 编程语言 > 详细

Java操作数组的类

时间:2014-11-30 21:42:41      阅读:285      评论:0      收藏:0      [点我收藏+]
public class MyArrayTool  {
	
	private Object items;
	private Collection collection;
	
	public void setItems(Object items) {  //collection
		this.items = items;  //list set
		if(items instanceof Collection){
			collection = (Collection) items;
		}
		if(items instanceof Map){
			Map map = (Map) items;
			collection = map.entrySet();
		}
		
		if(items.getClass().isArray()){
			collection = new ArrayList();
			for(int i=0;i<Array.getLength(items);i++){
				Object value = Array.get(items, i);
				collection.add(value);
			}
		}
		
	}
	
	public void test() {

		Iterator it = collection.iterator();
		while(it.hasNext()){
			Object value = it.next();
			System.out.print("value::"+value);
		}
	}
	
}


Java操作数组的类

原文:http://my.oschina.net/u/936286/blog/350547

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!