如何在Android中实现“每个”循环

时间:2019-04-11 10:34:32

标签: java foreach

请帮助我将此for循环更改为每个循环

for (int i: size) { ---我已经尝试过了,但是它不能在android studio中用作foreach循环。

int size = RecordManager.getInstance(CoCoinApplication.getAppContext()).RECORDS.size();
if (RecordManager.getInstance(CoCoinApplication.getAppContext()).SELECTED_RECORDS == null) {
    RecordManager.getInstance(CoCoinApplication.getAppContext()).SELECTED_RECORDS = new LinkedList<>();
}
RecordManager.getInstance(CoCoinApplication.getAppContext()).SELECTED_RECORDS.clear();
for (int i = 0; i < size; i++) {
    CoCoinRecord record = new CoCoinRecord();
    record.set(RecordManager.RECORDS.get(i));
    RecordManager.getInstance(CoCoinApplication.getAppContext()).SELECTED_RECORDS.add(record);
}

1 个答案:

答案 0 :(得分:1)

这是foreach循环,与您想要的完全一样:

for (CoCoinRecord record1: ecordManager.RECORDS) {
    CoCoinRecord record = new CoCoinRecord();
    record.set(record1);
    RecordManager.getInstance(CoCoinApplication.getAppContext()).SELECTED_RECORDS.add(record);
}