0
HashSet<String> outScopeActiveRegionCodeSet=new HashSet<String>();
for (String regionCode : outScopeActiveRegionCodeSet) {
    //code required
}   

ここでは、以下のようにループに動的に挿入された新しいTransactionLOgDTOオブジェクトを作成する必要があります。ハッシュセットに3つのリージョンコードがある場合、新しいオブジェクトの名前にregionCodeが追加された3つのTransactionLOgDTOオブジェクトが必要です。

TransactionLOgDTO regionCode1DTO=new TransactionLOgDTO(); 

}

このようなことをする必要があります..........................。

for (String regionCode : outScopeActiveRegionCodeSet) { TransactionLOgDTO "regionCode"+DTO=new TransactionLOgDTO(); } 
4

1 に答える 1

4

ArrayList変数名にインデックスを入れる代わりに、を使用することをお勧めします。

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);

[編集]
に接続したい場合はregionCodeTransactionLogDTO私がお勧めし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);
于 2012-07-20T10:03:45.770 に答える