1
I need to add lista.get(i)
in an array, will be added in the array with the value of key spec_linha-criativa
changed. However, in my code I always lose the reference and when j = 1
My list has the same values. For example, when the loop is executed: j = 0 the element 0 of the list is correct, when j = 1 the element 1 is correct but the element 0 becomes equal to 1. How to fix it? I already give the new on the object at each interaction to avoid this but occurs.
private List<BasicDBObject> linhaCriativa(List<BasicDBObject> linhas) {
List<BasicDBObject> lista = new ArrayList<>();
for (int i = 0; i < linhas.size(); i++) {
if (linhas.get(i).toMap().containsKey("spec_linha-criativa")) {
String[] linhaCriativa = linhas.get(i).get("spec_linha-criativa").toString().split(";");
if (linhaCriativa.length > 1) {
for (int j = 0; j < linhaCriativa.length; j++) {
BasicDBObject dbObject = new BasicDBObject();
dbObject = linhas.get(i);
dbObject.replace("spec_linha-criativa", linhaCriativa[j]);
lista.add(dbObject);
}
}
}
}
return lista;
}
I’ve had the same problem of "losing" reference but I can’t apply here https://stackoverflow.com/questions/29658869/why-cant-i-concatenate-the-json
lista
andlinha
will always be the same size?– Victor Stafusa
They are the same things, I brought by parameter twice to try to see if I could change.
– Daniela Morais