我建议使用 aArrayList
而不是将索引放在变量名中:
List<TransactionLOgDTO> regionCodeDTOs = new ArrayList<TransactionLOgDTO>();
HashSet<String> outScopeActiveRegionCodeSet=new HashSet<String>();
for (String regionCode : outScopeActiveRegionCodeSet) {
regionCodeDTOs.add(new TransactionLOgDTO());
}
或者,因为您没有使用regionCode
字符串:
List<TransactionLOgDTO> regionCodeDTOs = new ArrayList<TransactionLOgDTO>();
HashSet<String> outScopeActiveRegionCodeSet=new HashSet<String>();
for (int i = 0; i < outScopeActiveRegionCodeSet.size(); i++) {
regionCodeDTOs.add(new TransactionLOgDTO());
}
然后您可以使用以下方式访问它们:
regionCodeDTOs.get(i);
[编辑]
如果你想连接regionCode
到TransactionLogDTO
我会推荐一个Map instead
:
Map<String, TransactionLOgDTO> transactionCodeDTOs = new HashMap<String, TransactionLOgDTO>();
HashSet<String> outScopeActiveRegionCodeSet=new HashSet<String>();
for (String regionCode : outScopeActiveRegionCodeSet) {
transactionCodeDTOs.put(regionCode, new TransactionLOgDTO());
}
检索如下:
transactionCodeDTOs.get(regionCode);