我有一个看起来很蠢的问题,但已经停滞了3个小时。当我在arrayList中添加一个元素时,我不添加我应该添加的元素。
基本上在Sysout上,您可以看到我应该拥有的值,在B上的值上,您可以看到我仅添加了最后一个值...
private List<ContextSchemeValue> ConvertCodeListIntoContextSchemeValue (List<CodeListValue> A){
ContextSchemeValue C= new ContextSchemeValue();
List<ContextSchemeValue> B = new ArrayList<>();
for (int i = 0; i < A.size(); i=i+1) {
C.setContextScheme(contextScheme);
C.setMeaning(A.get(i).getName());
C.setValue(A.get(i).getValue());
System.out.println(" C"+i+" = "+C);
B.add(C);
}
System.out.println(" B =" + B);
return B;
}
C0 = ContextSchemeValue {ctxSchemeValueId = 0,guid ='null',value ='fefe',意思是'fefe',contextScheme = ContextScheme {ctxSchemeId = 0,guid ='null',schemeId ='null',schemeName ='null ',description ='null',schemeAgencyId ='2',schemeVersionId ='99999',contextCategory = null,createdBy = 0,lastUpdatedBy = 0,creationTimestamp = null,lastUpdateTimestamp = null}}
C1 = ContextSchemeValue {ctxSchemeValueId = 0,guid ='null',value ='efefewfeasf',含义='efewfw',contextScheme = ContextScheme {ctxSchemeId = 0,guid ='null',schemeId ='null',schemeName ='null ',description ='null',schemeAgencyId ='2',schemeVersionId ='99999',contextCategory = null,createdBy = 0,lastUpdatedBy = 0,creationTimestamp = null,lastUpdateTimestamp = null}}
C2 = ContextSchemeValue {ctxSchemeValueId = 0,guid ='null',value ='fef',意味着='fwefefef',contextScheme = ContextScheme {ctxSchemeId = 0,guid ='null',schemeId ='null',schemeName ='null ',description ='null',schemeAgencyId ='2',schemeVersionId ='99999',contextCategory = null,createdBy = 0,lastUpdatedBy = 0,creationTimestamp = null,lastUpdateTimestamp = null}}
我真的不明白为什么add函数会不断添加最后一个值,而不是另一个,我在每个i上打印了该值,非常感谢您的帮助!
慕容森
相关分类