java 数组去掉连续重复出现元素并且只保留一个
比如有数组Stringa[]={"1","2","2","3","3","3","6"};处理之后变成数组Stringa[]={"1","2","3","6"};...
比如有数组 String a[] ={"1","2","2","3","3","3","6"};
处理之后变成数组 String a[] ={"1","2","3","6"}; 展开
处理之后变成数组 String a[] ={"1","2","3","6"}; 展开
1个回答
展开全部
public static void main(String[] args) throws ParseException {
String[] a ={"1","2","2","3","3","3","6"};
TreeSet set = new TreeSet();
for(String s:a) {
set.add(s);
}
String[] array = (String[])set.toArray(new String[]{});
System.out.println(Arrays.toString(array));
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询