我有一个带有重复元素的ArrayList
of 。Strings
每 3 行构成一个实体:
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
所有元素都是Strings
. 第一个数字表示参与者的数量,第二个表示价值,第三个表示组成它的元素。所以我有重复
3 550111.55 3, 1, 2
和
3 550111.55 1、2、3
和
3 550111.55 2、3、1
元素的数量表示重复的数量,因此我必须删除所有重复项,在这种情况下,删除除一个实例之外的所有实例,例如:
3 550111.55 2、3、1
我正在尝试这样做:
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;
}
所以我希望有更好的方法......