集合第八发练习之容器版V2.0
2016-03-26 12:52
274 查看
一、Clooection
package cn.hncu.MySet3; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import cn.hncu.collectionDemo.collectionDemo; public class MyCollection { private Collection col=new ArrayList(); public boolean add(Object obj){ col.add(obj); return true; } public boolean update(Object oldObj,Object newObj){ Object objs[]=col.toArray(); col.clear(); for(int i=0;i<objs.length;i++){ if(objs[i].equals(oldObj)){ objs[i]=newObj; } col.add(objs[i]); } return true; } public boolean delete(Object obj){ return col.remove(obj); } public Collection getAll(){ return col; } public Collection getByConditon(String str){ Collection result=new ArrayList(); Iterator it=col.iterator(); while(it.hasNext()){ if(it.next().toString().indexOf(str)>=0){//模糊查询 result.add(it); } } return result; } }
二、Map
package cn.hncu.MySet3; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import java.util.Set; public class MyMap { private Map map=new HashMap(); public boolean add(Object key,Object value) { map.put(key, value); return true; } public Object delete(Object key){ return map.remove(key); } public Map select(String key){ Map result=new HashMap(); Set set=map.entrySet(); Iterator it=set.iterator(); while(it.hasNext()){ Entry entry=(Entry) it.next(); if(entry.getKey().toString().indexOf(key)>=0){ result.put(entry.getKey(), entry.getValue()); } } return result; } public Map getAll(){ return map; } }
相关文章推荐
- codeforces 651B Beautiful Paintings
- Android开发工具
- 《Linux Device Drivers》第十章 中断处理——note
- Android 上拉面板 AndroidSlidingUpPanel
- posix线程使用详解
- JavaScript编程全解学习日记 一
- 17. Letter Combinations of a Phone Number
- C#第二次上机
- 【资源汇集.转】C++编程学习52个经典网站 强力推荐
- httpclient4.3 工具类
- 动态规划(1)——算法导论(16)
- 0326第四周学习进度条
- 第三周项目4—程序分析
- J2EE sitemesh使用
- MATLAB编译c++出错的解决办法(Error in compile (line 439) mex(args{:});)
- Windows 常用命令
- (转)imageButton src&backGround属性
- 享元模式
- WiFi万能钥匙电脑版官网下载地址
- 一步步学会Thrift服务搭建和调用