几种去除数组中重复元素的方法,数组去重

2024-12-18 02:42:03
推荐回答(1个)
回答1:

import java.util.*;

class BaiDu
{
public static void main(String[] args)
{
TreeSet tr = new TreeSet();
String[] s ={"11","22","22","33","33","33"};
System.out.print("====处理前=======");
for(int i=0;iSystem.out.print(s[i]+" ");
tr.add(s[i]);

}
String[] s2= new String[tr.size()];
System.out.println("=====处理后======");
for(int i=0;is2[i]=tr.pollFirst();//从TreeSet中取出元素重新赋给数组
System.out.print(s2[i]+" ");
}
}
}