我正在尝试ArrayList
从现有内容中获取新内容ArrayList
并更新新列表中的字段。但它也在旧列表中得到更新。
我尝试了以下代码:
absoluteEntitlements = findAbsoluteEntitlements(ImmutableList.copyOf(tenantEntitlements), everyoneEntitlements, "global");
private List<Entitlement> findAbsoluteEntitlements(ImmutableList<Entitlement> primaryEntitlements,
List<Entitlement> secondaryEntitlements, String accessType) {
List<Entitlement> absoluteEntitlements = new ArrayList<Entitlement>(primaryEntitlements);
for (int i = 0; i < primaryEntitlements.size(); i++) {
for (int j = 0; j < secondaryEntitlements.size(); j++) {
if (secondaryEntitlements.get(j).equals(primaryEntitlements.get(i))
&& "false".equals(primaryEntitlements.get(i).getAccessType())) {
absoluteEntitlements.get(i).setAccessType(accessType);
}
}
}
return absoluteEntitlements;
}
请提供一个解决方案,我做错了。