Object []a={“aa”,1}; |
|
40分 |
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)); } } } |
敬佩,
|