M
Marcel.luchi
Hi there, please can anyone help me?
Im having troubles when adding objects to an ArrayList.
This is the Code:
public ArrayList <Especie> parse (ArrayList <String> vec) {
ArrayList <Especie> individuos = new ArrayList <Especie>
();
int inter[] = new int [17];
int vecsize = vec.size ();
for (int i = 0; i < vecsize; i++) {
String carac[] = vec.get (i).toString ().split (",") ;
for (int j=0; j<17; j++) {
inter[j] = Integer.parseInt (carac[j+1]);
}
individuos.add (new Especie (inter));
}
for(Especie e: individuos){
for(int i=0; i<17; i++){
}
}
return individuos;
}
What happens is that the Objects Especie are being created correctly,
but when i add it to the ArrayList individuos, the last created
Especie is added N times to the ArrayList.
I think the proplem is in the line
individuos.add(new Especie(inter));
but dun know what is wrong in it.
Tnx.
Marcel Luchi Marchi
Im having troubles when adding objects to an ArrayList.
This is the Code:
public ArrayList <Especie> parse (ArrayList <String> vec) {
ArrayList <Especie> individuos = new ArrayList <Especie>
();
int inter[] = new int [17];
int vecsize = vec.size ();
for (int i = 0; i < vecsize; i++) {
String carac[] = vec.get (i).toString ().split (",") ;
for (int j=0; j<17; j++) {
inter[j] = Integer.parseInt (carac[j+1]);
}
individuos.add (new Especie (inter));
}
for(Especie e: individuos){
for(int i=0; i<17; i++){
}
}
return individuos;
}
What happens is that the Objects Especie are being created correctly,
but when i add it to the ArrayList individuos, the last created
Especie is added N times to the ArrayList.
I think the proplem is in the line
individuos.add(new Especie(inter));
but dun know what is wrong in it.
Tnx.
Marcel Luchi Marchi