算是明白了用addall结合hashset能直接就能过掉重复的的数据!作者: 徐军涛 时间: 2012-11-25 09:09
----------------
赶早起来第一件正事,就是昨天的问题,谁知道,还给解决了,{:soso_e109:}
-----------------
public class TreeSet {
public static void main(String[] args) throws Exception {
Collection<Integer> coll = new java.util.TreeSet<>();
int count = 100;
for(int i = 0;i<count;i++){
coll.add(new Random().nextInt(10));
}
//获取键盘录入
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
int trans = Integer.parseInt(str);
coll.add(trans);
//把集合转化成数组
int [] arr = new int [coll.size()];
Iterator< Integer> it = coll.iterator();
int i =0;
while(it.hasNext()){
arr[i] = it.next();
i++;
}
for(int x = 0;x<arr.length;x++){
System.out.println(arr[x]);
}