Map集合的定义
HashMap<Integer,String[]> columnValueList = new HashMap<Integer,String[]>();
HashMap<String,String> primaryMap = new HashMap<String,String>();
primaryMap.put(fieldName, fieldOrder.toString());
String[] columnValue = new String[3];
columnValue[0]=fieldName;
columnValue[2]=fieldDataType;
columnValueList.put(fieldOrder-1,columnValue);
String [] sqls = new String[sheet.getLastRowNum()];
condictionSql = "INSERT INTO "+templateTable+"("+paramkey.toString()+") VALUES( "+paramval.toString()+")";
}
sqls[i-1] = condictionSql;
for循环遍历Map集合
for (Iterator<Entry<String, String>> pm = primaryMap.entrySet().iterator(); pm.hasNext(); ) {
Entry<String, String> entry = (Entry<String, String>) pm.next();
//如果是无线新增操作
if(templateActionField == null){
paramPrimarykey.append(",").append(entry.getKey());
String pkVal = CommonUtils.getUUID();
paramSubval.append(",").append("'"+pkVal+"'");
primaryMapVal.add(pkVal);
}else {
paramPrimarykey.append(",").append(entry.getKey());
String pkVal = CommonUtils.getUUID();
paramSubval.append(",").append("'"+pkVal+"'");
primaryMapVal.add(pkVal);
busPrimaryKey = templateActionField;
}
if(paramPrimarykey.indexOf(",")==0){
paramkey = paramkey.append(paramPrimarykey.substring(1));
}
if(paramSubval.indexOf(",")==0){
paramval = paramval.append(paramSubval.substring(1));
}
}
for (Iterator<Entry<Integer, String[]>> it = columnValueList.entrySet().iterator(); it.hasNext(); ) {
Entry<Integer, String[]> entry = (Entry<Integer, String[]>) it.next();
String[] entryValue = entry.getValue();
paramkey.append(",").append(entryValue[0]);
paramval.append(",").append(entryValue[1]);
}
foreach遍历map集合
Map<String, List<FastEntryVO>> fastEntryMap = getFastEntryDtoMap(fastEntryList);
List<FastEntryDto> fastEntryDtoList = new ArrayList<FastEntryDto>(1);
FastEntryDto fastEntryDto = null;
for (Map.Entry<String, List<FastEntryVO>> entry : fastEntryMap.entrySet())
{
for (FastEntryVO fastEntry : fastEntryList)
{
if (fastEntry.getFastEntryId().equals(entry.getKey()))
{
fastEntryDto = new FastEntryDto();
BeanUtils.copyProperties(fastEntry, fastEntryDto);
fastEntryDto.setFastEntryList(entry.getValue());
fastEntryDtoList.add(fastEntryDto);
break;
}
}
}
return fastEntryDtoList;
}
private Map<String, List<FastEntryVO>> getFastEntryDtoMap(List<FastEntryVO> fastEntryList) {
Map<String, List<FastEntryVO>> entryMap = new HashMap<String, List<FastEntryVO>>(1);
List<FastEntryVO> secondEntryList = null;
FastEntryVO entry = null;
for (FastEntryVO fastEntry : fastEntryList) {
if (fastEntry.getParentId().equals("-1")) {
continue;
}
entry = new FastEntryVO();
BeanUtils.copyProperties(fastEntry, entry);// 复制属性
if (entryMap.containsKey(fastEntry.getParentId())) {
secondEntryList = entryMap.get(fastEntry.getParentId());
secondEntryList.add(entry);
} else {
secondEntryList = new ArrayList<FastEntryVO>(1);
secondEntryList.add(entry);
entryMap.put(fastEntry.getParentId(), secondEntryList);
}
}
return entryMap;
}
list初始化
List<String> items = new ArrayList<String>();
items.add(questionITA);
items.add(questionITB);
items.add(questionITC);
items.add(questionITD);
遍历list集合
for(int m=0;m<=items.size()-1;m++) {
String itemCon = items.get(m);
}
list集合与map集合的组装
public List<CheckAdvice> removePicExtra(List<CheckAdvice> picList,List<CheckAdvice> list) {
List<CheckAdvice> newList= new ArrayList<CheckAdvice>();
HashMap<String, String> hashMap = new HashMap<String, String>();
for (CheckAdvice checkAdvice : picList) {
if (checkAdvice == null) {
continue;
}
String adviceId = checkAdvice.getAdviceId();
if (adviceId != null) {
String value = hashMap.get(adviceId);
if (StringUtil.isEmpty(value)) { //如果value是空的 说明取到的这个adviceId是第一次取到
hashMap.put(adviceId, adviceId);
} else {
continue;
}
}
}
for (CheckAdvice checkAdvice : list) {
if (checkAdvice == null) {
continue;
}
String adviceId = checkAdvice.getAdviceId();
if (adviceId != null) {
String value = hashMap.get(adviceId);
if (StringUtil.isEmpty(value)) { //如果value是空的 说明取到的这个adviceId是第一次取到
hashMap.put(adviceId, adviceId);
newList.add(checkAdvice);
} else {
continue;
}
}
}
hashMap.clear();
return newList;
}