我得到具有6列的resultSet。现在,我将其分配给对象数组列表。事实是列表中每个对象的Object [4]可以为null,也可以不为null。
如果它具有空值,则必须使用字符串常量“ System”进行设置。
如何使用Java 8做到这一点?请协助!
List<Object[]> loanEntries = loanDAO.getLoanMappingDetails(QueryConstants.LOAN_MAPPING);
最佳答案
我了解到loanEntries是您正在谈论的变量。
List<Object[]> loanEntries = new ArrayList<>();
loanEntries.add(new Object[]{"a","b","c","d",null,"f"});
loanEntries.add(new Object[]{"aa","bb","cc","dd",null,"ff"});
loanEntries.stream()
.filter(objects -> objects[4] == null)
.forEach(objects -> objects[4] = "System");
loanEntries.stream()
.forEach(objects -> {
for (Object object : objects) {
System.out.println(object);
}
});
输出
a
b
c
d
System
f
aa
bb
cc
dd
System
ff