Object []a={"aa",1};
Object []b={"bb",2};
Object []c={"ax",3};
Object []d={"aa",4};
Object []e={"bd",5};
Object []f={"f",6};
List list=new ArrayList();
list.add(a);
list.add(b);
list.add(c);
list.add(d);
list.add(e);
list.add(f);
取到第一个字符,其他数组相同位置的字符一样则将其修改为“ ”如:
Object []a={"aa",1}; Object []c={"ax",3};Object []d={"aa",4};
结果
Object []a={"aa",1}; Object []c={" ",3};Object []d={" ",4};
------解决方案--------------------
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Test6 {
public static void main(String args[]){
Object []a={"aa",1};
Object []b={"bb",2};
Object []c={"ax",3};
Object []d={"aa",4};
Object []e={"bd",5};
Object []f={"f",6};
List<Object[]> list=new ArrayList<Object[]>();
list.add(a);
list.add(b);
list.add(c);
list.add(d);
list.add(e);
list.add(f);
for(int i=0;i<list.size();i++){
Object[] temp = list.get(i);
String firstStr = String.valueOf(temp[0]).substring(0, 1);
for(int j=i+1;j<list.size();j++){
Object[] temp1 = list.get(j);
String firstStr_inner = String.valueOf(temp1[0]).substring(0, 1);
if(firstStr.equals(firstStr_inner)){
list.set(j, new Object[]{" ",temp1[1]});
}
}
}
for(int i=0;i<list.size();i++){
Object[] temp = list.get(i);
System.out.println(Arrays.toString(temp));
}
}
}