有这样一个题目,大家先凭脑经想想看,写出答案,再用机器编码实际测试一下,看看输出结果,对比一下,看看有什么发现。
QUESTION:一个List unitList有3条记录:
id,unitid,unitname
1,JS001,江苏
2,JS002,南京
3,JS003,白下
分别有以下三段代码,写出每段代码的输出结果。
//----------------------------------------------------------------
Logger logger = Logger.getLogger(this.getClass().getName());
List unitList = unitService.getObjectPageList(parameterObj, 1, 3);
ArrayList tmpList = new ArrayList();
Hashtable tmpTable = new Hashtable();
UnitEntity tmpUnit = null;
for (int i = 0; i < unitList.size(); i++) {
tmpUnit = (UnitEntity) unitList.get(i);
tmpTable.put("id", tmpUnit.getId().toString());
tmpTable.put("unitid", tmpUnit.getUnitid());
tmpTable.put("unitname", tmpUnit.getUnitcode());
tmpList.add(tmpTable);
}
logger.debug(tmpList);
//----------------------------------------------------------------
Logger logger = Logger.getLogger(this.getClass().getName());
List unitList = unitService.getObjectPageList(parameterObj, 1, 3);
ArrayList tmpList = new ArrayList();
Hashtable tmpTable = new Hashtable();
for (int i = 0; i < unitList.size(); i++) {
UnitEntity tmpUnit = (UnitEntity) unitList.get(i);
tmpTable.put("id", tmpUnit.getId().toString());
tmpTable.put("unitid", tmpUnit.getUnitid());
tmpTable.put("unitname", tmpUnit.getUnitcode());
tmpList.add(tmpTable);
}
logger.debug(tmpList);
//----------------------------------------------------------------
Logger logger = Logger.getLogger(this.getClass().getName());
List unitList = unitService.getObjectPageList(parameterObj, 1, 3);
ArrayList tmpList = new ArrayList();
for (int i = 0; i < unitList.size(); i++) {
UnitEntity tmpUnit = (UnitEntity) unitList.get(i);
Hashtable tmpTable = new Hashtable();
tmpTable.put("id", tmpUnit.getId().toString());
tmpTable.put("unitid", tmpUnit.getUnitid());
tmpTable.put("unitname", tmpUnit.getUnitcode());
tmpList.add(tmpTable);
}
logger.debug(tmpList);
//----------------------------------------------------------------
比较一下结果,看看有什么发现。
QUESTION:一个List unitList有3条记录:
id,unitid,unitname
1,JS001,江苏
2,JS002,南京
3,JS003,白下
分别有以下三段代码,写出每段代码的输出结果。
//----------------------------------------------------------------
Logger logger = Logger.getLogger(this.getClass().getName());
List unitList = unitService.getObjectPageList(parameterObj, 1, 3);
ArrayList tmpList = new ArrayList();
Hashtable tmpTable = new Hashtable();
UnitEntity tmpUnit = null;
for (int i = 0; i < unitList.size(); i++) {
tmpUnit = (UnitEntity) unitList.get(i);
tmpTable.put("id", tmpUnit.getId().toString());
tmpTable.put("unitid", tmpUnit.getUnitid());
tmpTable.put("unitname", tmpUnit.getUnitcode());
tmpList.add(tmpTable);
}
logger.debug(tmpList);
//----------------------------------------------------------------
Logger logger = Logger.getLogger(this.getClass().getName());
List unitList = unitService.getObjectPageList(parameterObj, 1, 3);
ArrayList tmpList = new ArrayList();
Hashtable tmpTable = new Hashtable();
for (int i = 0; i < unitList.size(); i++) {
UnitEntity tmpUnit = (UnitEntity) unitList.get(i);
tmpTable.put("id", tmpUnit.getId().toString());
tmpTable.put("unitid", tmpUnit.getUnitid());
tmpTable.put("unitname", tmpUnit.getUnitcode());
tmpList.add(tmpTable);
}
logger.debug(tmpList);
//----------------------------------------------------------------
Logger logger = Logger.getLogger(this.getClass().getName());
List unitList = unitService.getObjectPageList(parameterObj, 1, 3);
ArrayList tmpList = new ArrayList();
for (int i = 0; i < unitList.size(); i++) {
UnitEntity tmpUnit = (UnitEntity) unitList.get(i);
Hashtable tmpTable = new Hashtable();
tmpTable.put("id", tmpUnit.getId().toString());
tmpTable.put("unitid", tmpUnit.getUnitid());
tmpTable.put("unitname", tmpUnit.getUnitcode());
tmpList.add(tmpTable);
}
logger.debug(tmpList);
//----------------------------------------------------------------
比较一下结果,看看有什么发现。