I have an ArrayList
of Strings
with duplicate elements. Every 3 rows make an entity:
2 550111.55 1, 3
3 550111.55 1, 2, 3
2 155.55 1, 2
3 550111.55 2, 3, 1
2 155.55 2, 1
2 550111.55 3, 1
3 550111.55 3, 1, 2
All the elements are Strings
. The first number says the number of participants, the second says the value, and the third which elements make it up.
So I have duplicates like
3 550111.55 3, 1, 2
and
3 550111.55 1, 2, 3
and
3 550111.55 2, 3, 1
The number of elements says the number of duplicates, so I must remove all the duplicates, in this case, delete all but one instance, for example:
3 550111.55 2, 3, 1
I am trying to do it like this :
ArrayList<String> lista_rezultata1=new ArrayList<String>();
lista_rezultata1=lista_rezultata;
//set to count to 3 in arraylist since data I need to split and evaluate are always on the third place
int number1=0;
int number2=0;
String[] part1=null;
String[] part2=null;
int removefromlist=0;
for (int i = 0; i < lista_rezultata.size(); i++) {
if(number1==3)number1=0;
if(number1==2)//If it is a third element it is the one with "," that I split
{
part1=lista_rezultata.get(i).toString().split(",");
}
for (int j = 0; j < lista_rezultata1.size(); j++) {
if(number2==3)number2=0;
if(number2==2 && i!=j && number1==2)//If it is a third element it is the one with "," that I split, first must already be splited
{
part2=lista_rezultata1.get(j).toString().split(",");
for (int k = 0; k < part1.length; k++) {
for (int l = 0; l < part2.length; l++) {
if(part1.length==part2.length) //if they have the same number of elements
{
if(part2[l].equals(part1[j]))
{
.....some code
}
}
}
}
}
number2=number2+1;
}
number1=number1+1;
}
So I am hoping there is a better way ...