Consider having 3 lists. One of modObj != null && modObj.isMod()
. Another one of modObj != null && !modObj.isMod()
. Third one of the rest (aka modObj == null
). Finally join them. E.g.:
List<Data> front_list = new ArrayList<>();
List<Data> mid_list = new ArrayList<>();
List<Data> tail_list = new ArrayList<>();
for (Data d: basicData) {
Data modObj = modData.get(d.getId());
if (modObj == null) {
tail_list.appendadd(d);
} else if (modObj.isMod()) {
front_list.appendadd(modObj);
} else {
mid_list.appendadd(modObj);
}
}