iOS去除数组中重复元素的几种方法
1个回答
展开全部
import java.util.*;
class BaiDu
{
public static void main(String[] args)
{
TreeSet<String> tr = new TreeSet<String>();
String[] s ={"11","22","22","33","33","33"};
System.out.print("====处理前=======");
for(int i=0;i<s.length;i++){
System.out.print(s[i]+" ");
tr.add(s[i]);
}
String[] s2= new String[tr.size()];
System.out.println("=====处理后======");
for(int i=0;i<s2.length;i++){
s2[i]=tr.pollFirst();//从TreeSet中取出元素重新赋给数组
System.out.print(s2[i]+" ");
}
}
}
class BaiDu
{
public static void main(String[] args)
{
TreeSet<String> tr = new TreeSet<String>();
String[] s ={"11","22","22","33","33","33"};
System.out.print("====处理前=======");
for(int i=0;i<s.length;i++){
System.out.print(s[i]+" ");
tr.add(s[i]);
}
String[] s2= new String[tr.size()];
System.out.println("=====处理后======");
for(int i=0;i<s2.length;i++){
s2[i]=tr.pollFirst();//从TreeSet中取出元素重新赋给数组
System.out.print(s2[i]+" ");
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询