0
I’m making a code to be able to remove duplicate lines from a vector with customer registrations.
This vector is "tabela[1000][3]
"
So I have for example:
1ºlinha - "joao" " rua: asasdfasdfs" "cep: 21412354125"
2ºlinha - "matheus" " rua: asdfasdfasdf" "cep: 21412354125"
3ºlinha repetida - "jonas" " rua: asdfasdf" "cep: 21412354125"
4ºlinha - "guilherme" " rua: asdfasdfasdf" "cep: 21412354125"
5ºlinha - "gabriel" " rua: asasdfasdfasdfasdfs" "cep: 21412354125"
6ºlinha repetida - "jonas" " rua: asdfasdf" "cep: 21412354125"]
there are names of the first column that are repeated, and I would like to remove that row altogether, so I thought I would make a new vector only with non-repeated lines comparing row by row of the vector that would be filtered with the old:
int filt_next = 0;
for(int atual = 0; atual < tabela.length; atual++){
for(int passando = 0; passando < filtrado.length; passando++){
String comp1 = tabela[atual][0];
String comp2 = filtrado[passando][0];
if(comp1 == comp2){
break;
}
if(comp1 != comp2){
filtrado[filt_next][0] = tabela[atual][0];
filtrado[filt_next][1] = tabela[atual][1];
filtrado[filt_next][2] = tabela[atual][2];
filt_next++;
break;
}
}
}
The idea is that if the position of the first vector is equal to that of the second vector it would just break out of the loop, ignoring the repetition. And if it passes through all positions and is different it would add such a position in the new vector.
However the part that should take the equal positions is ignored, and the equal Strings are considered different, being added to the filter vector.
if(comp1 == comp2){
break;
}
I can’t understand what I’ve done wrong.
Comparison of
Strings
in java is withequals
and not with==
. It’s still unclear what exact information the file has. And better solution would be as it reads lines from the file does not add to a client list if the client already exists, and then just have to rewrite the clients it has read– Isac
the table has 3 columns, and the first column has the name of the clients, I just need to compare this first column, without losing the order of the data of the other 2 columns... and not put the lines in a vector to compare it later?
– Kelvin Crepaldi