这是个数组去重的题给定 指定数组 {6,9,8,4,6,8,4,5,2,7}要去掉重复的得到{6,9,8,4,5,2,7},
但下面代码运行后,给做了排序{2,4,5,6,7,8,9},能不能做到原数组的排序,不要大小写的,
请高手看看,那里出错了,或者给个其他方法,
- import java.util.*;
- class Test01 {
- public static void main(String[] args) {
- TreeSet ts = new TreeSet();
- int[] array = new int[]{6,9,8,4,6,8,4,5,2,7};
- System.out.print("原数组:");
- System.out.println(Arrays.toString(array));
- for (int i = 0; i < array.length; i++) {
- ts.add(array);
- }
- System.out.print("去重后:");
- System.out.println(ts);
- }
-
|