java中三个for循环嵌套查询,每个集合的size()大小不同?取值做判断,会产生许多冗余数据?如何避免?timeList.size()是66,callBarsList.size()是22,currentList.size()是20;分别取值做判断,会循环好多遍,如何能

来源:学生作业帮助网 编辑:六六作业网 时间:2024/05/07 05:43:23
java中三个for循环嵌套查询,每个集合的size()大小不同?取值做判断,会产生许多冗余数据?如何避免?timeList.size()是66,callBarsList.size()是22,curr

java中三个for循环嵌套查询,每个集合的size()大小不同?取值做判断,会产生许多冗余数据?如何避免?timeList.size()是66,callBarsList.size()是22,currentList.size()是20;分别取值做判断,会循环好多遍,如何能
java中三个for循环嵌套查询,每个集合的size()大小不同?取值做判断,会产生许多冗余数据?如何避免?
timeList.size()是66,callBarsList.size()是22,currentList.size()是20;
分别取值做判断,会循环好多遍,如何能够控制循环的次数,只让满足条件的数据循环一遍?
for (int j = 0; j < timeList.size(); j++) {
for (int k = 0; k < callBarsList.size(); k++) {
for (int k2 = 0; k2 < currentList.size(); k2++) {
int timeWeekMonth = timeList.get(j).getWeekendingmonth();
int timeWeekDay = timeList.get(j).getWeekendingday();
int current = currentList.get(k2).getCurrentID();
if (callBarsList.get(k).getWeek() == timeList.get(j).getWeek()
&& callBarsList.get(k).getYear().intValue() == timeList.get(j).getYear().intValue()
&& current == callBarsList.get(k).getId()) {
Integer count = callBarsList.get(k).getCount();
String description = callBarsList.get(k).getDescription();
String theDate = timeWeekMonth + "/" + timeWeekDay;
dataset.setValue(count,description,theDate);
}else{
String description=callBarsList.get(k).getDescription();
String theDate= timeWeekMonth+"/"+timeWeekDay;
dataset.setValue(0,description,theDate);
}
}
}
}

java中三个for循环嵌套查询,每个集合的size()大小不同?取值做判断,会产生许多冗余数据?如何避免?timeList.size()是66,callBarsList.size()是22,currentList.size()是20;分别取值做判断,会循环好多遍,如何能
这个三重循环肯定会降低性能.循环次数是66*22*20次.另外计算集合的大小应该放到循环外边声明,避免每次循环都重新计算其大小.如果你用的jdk版本是5.0以上,建议你用for-each循环结构.
改良的代码如下:循环次数是66+22+20
Map callBarMap = new HashMap();
int callBarsize = callBarsList.size();
for (int k = 0; k < size; k++) {
map.put( callBarsList.get(k).getWeek() +","+callBarsList.get(k).getYear().intValue(),callBarsList.get(k));
}
Map currentMap = new HashMap();
int currentSize = currentList.size();
for (int k2 = 0; k2 < currentSize; k2++){
currentMap.put(currentList.get(k2).getCurrentID(),currentList.get(k2));
}
int timeSize = timeList.size();
for (int j = 0; j < timeSize; j++) {
int timeWeekMonth = timeList.get(j).getWeekendingmonth();
int timeWeekDay = timeList.get(j).getWeekendingday();
CallBars callBars =map.get(timeList.get(j).getWeek()+","+timeList.get(j).getYear().intValue);
if(callBars !=null){
Current current = currentMap.get(callBars.getId());
if(current!=null){
Integer count = callBars.getCount();
String description = callBars.getDescription();
String theDate = timeWeekMonth + "/" + timeWeekDay;
dataset.setValue(count,description,theDate);
}else{
String description=callBars.getDescription(); String theDate= timeWeekMonth+"/"+timeWeekDay;
dataset.setValue(0,description,theDate);
}
}
}
}

java中三个for循环嵌套查询,每个集合的size()大小不同?取值做判断,会产生许多冗余数据?如何避免?timeList.size()是66,callBarsList.size()是22,currentList.size()是20;分别取值做判断,会循环好多遍,如何能 在c#语言中for循环嵌套switch循环,switch循环中有break,它终止for循环还是switch 对于for循环中嵌套了if结构的流程图怎么画呢? 用java写一个嵌套的for循环打印下列图案:1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 写一个嵌套的for循环打印下列图案: java中for循环有两种形式 一种是for(int i=0;i C语言中while(1)中嵌套一个for循环,那么for循环会被一直反复执行吗?for循环执行一遍以后里面变量不是已经改变了吗,它会还原吗 用嵌套的循环语句,分别边写程序打印下列4个图案.JAVA语言 用嵌套的循环语句,分别边写程序打印下列图案JAVA语言 用嵌套的循环语句,分别边写程序打印下列图案.20 | 离问题结束还有 14 天 23 java 简单二维数组练习题利用二维数组实现以下图形的输出********想利用二维数组,嵌套循环也需要二维数组赋值,嵌套循环不会使用呀,麻烦各位大侠给写下 for循环语句括号的问题 有人说for应该都加{} 循环嵌套的大括号应该给外循环还是内循环啊 用java中的(for循环)打印如下三角形图形: ***** **** *** ** * 用java程序写出使用for循环打印下面图形 编写java程序,应用for循环打印菱形. 如何用java的for循环做一个等腰三角形? c语言中 for循环嵌套的运算流程?for(表达式1,表达式2,表达式3)//for1for(表达式1,表达式2,表达式3)//for2for1的表达式3是在for2的运算后还是运算前还是运算中? Java.for循环问题(1)使用for循环实现:输出100以内的奇数.(2)使用for循环实现:统计0~100中的整数中有多少个是7的倍数 利用for循环嵌套编写程序,计算1!+2!+3!+……+n!,要求n的值要由键盘输入 一定要用嵌套 vb题目在嵌套循环的for循环中如何计算循环次数比如:s=0for x=0 to 50 for y=0 to50 z=30-x-y if x 2*y 5*z=100 and z>=0 then s=s 1 next ynext x