List、Set及Map的读取数据---Iterator遍历
来源:互联网 发布:新东方网络视频课怎样 编辑:程序博客网 时间:2024/05/16 19:21
¨
List和Set都是Collection的子接口,区别如下:
Set是一个不包含重复元素的集合,集合内数据没有顺序
List通常被称作序列,允许重复元素,内部元素有特定的顺序
一开始,当然不能忘了最初的操作集合的方法
List<Integer> list=new List<Integer>();
for (int i=0; i<50000; i++) {
list.add(11);
}
int resutl = 0;
for (int i=0; i< list.size(); i++) {
resutl = list.get(i);
}
或者用更高效率的增强的for循环进行遍历(增强for循环和iterator遍历的效果是一样的,也就说增强for循环的内部也就是调用iteratoer实现的)
for (int c2 : list) {
System.out.println(c2);
}
关于list、Set和map循环读取数据
1.list读取数据:
Query query = session.createQuery(hql);
query.setParameter(0, policyNumber);
List list = query.list();
if (list != null && list.size() > 0) {
Iterator it = list.iterator();
while (it.hasNext()) {
TPolicyensure tpolicyEnsure = (TPolicyensure) it.next();
map.put(tpolicyEnsure.getId().getEnsureCode(),DoubleUtil.format(tpolicyEnsure.getInsurance(),2));
map.put("name_"+tpolicyEnsure.getId().getEnsureCode(),
tpolicyEnsure.getEnsureShort());
}
}
-----------------------------------------------------------------------------------------------------------------------------------
List policylist = service.queryVStatistic(start, parm);
List allPolicyList = service.queryVStatisticAll(parm);
List wsbPolicyList = new ArrayList();
List notWsbPolicyList = new ArrayList();
String wsbProducts=((String)ConstantService.getValue("minoramt","sh_wsb_products",null));
String[] wps = wsbProducts.split(",");
for(Iterator<VStatistic> it = allPolicyList.iterator(); it.hasNext(); ){
VStatistic vs = it.next();
if(vs.getPolicyNo().startsWith("HAZ") ){
wsbPolicyList.add(vs);
} else {
boolean flag =false;
for(String wp : wps) {
if(wp.equalsIgnoreCase(vs.getProductCode())) {
flag = true;
wsbPolicyList.add(vs);
}
}
if(flag ==false){
notWsbPolicyList.add(vs);
}
}
==================================================================================
2.Set读取数据:(同List)
===============================================================================
3.Map读取数据:
Map<String, Object> map = new HashMap<String, Object>();
EpolicyDAO dao = new EpolicyDAO();
map = dao.getEpolicyEnsure(policy.getPolicyNo());
Iterator<Entry<String, Object>> iter = map.entrySet().iterator();
while (iter.hasNext()){
Entry<String, Object> entry = iter.next();
String key = entry.getKey();
String value = null;
if("01".equals(key)||"02".equals(key)||"03".equals(key)||"04".equals(key)
||"05".equals(key)||"06".equals(key)||"07".equals(key)||"08".equals(key)){
String val = entry.getValue().toString();
//数据格式化 ###,### (去掉小数点后的零,如12345.00--->12,345)
value = new DecimalFormat(",###").format(Long.valueOf(val.substring(0, val.length()-3)));
}
if ("01".equals(entry.getKey())) {
VV.setInsurancePremium1(value);
}
if ("02".equals(entry.getKey())) {
VV.setInsurancePremium2(value);
}
if ("03".equals(entry.getKey())) {
VV.setInsurancePremium3(value);
}
if ("04".equals(entry.getKey())) {
VV.setInsurancePremium4(value);
}
if ("05".equals(entry.getKey())) {
VV.setInsurancePremium5(value);
}
if ("06".equals(entry.getKey())) {
VV.setInsurancePremium6(value);
}
if ("07".equals(entry.getKey())) {
VV.setInsurancePremium7(value);
}
if ("08".equals(entry.getKey())) {
VV.setInsurancePremium8(value);
}
}
===================================================================
- List、Set及Map的读取数据---Iterator遍历
- set,list,map的遍历
- List, Map, Set与Iterator的使用
- 遍历list map set
- List 、Set 、Map 的遍历方式
- List、Set、Map的遍历方法
- Map、Set、List集合的遍历
- List,Map,Stack,Queue,Set的遍历
- List、Set集合Map集合的遍历
- list,map,set的遍历以及排序
- 集合List、Set、Map的遍历方式
- List、Set和Map的遍历方法
- Map集合,List集合,Array数组,Iterator迭代,Collection集合,Set集合的多种遍历方式
- java的集合-List-Map-Set遍历的方法及相互的区别
- jstl 遍历 List,Set,Map
- java list set map 遍历
- 4.1 Collection,List,Set,Iterator,Map
- Java容器(List、Map、Set、Iterator)
- Vb.net多行注释快捷键方法
- 大文件的处理
- jquery.fn.extend与jquery.extend
- 如何保持http会话
- nutch和lucene的区别
- List、Set及Map的读取数据---Iterator遍历
- Android中RelativeLayout各个属性的含义
- Oracle 中关于 sequence 对象的使用限制
- 2013/2/25
- JavaScript知识点之“事件机制”
- JQuery 中的ajax
- c++ primer 第九章39题
- Hibernate中如何只更新修改过的字段,未修改的字段不用更新??(3中方法) .
- (转)android:minSdkVersion 之我见