就这么个样。没有思路阿
能告诉我大概要用到那些api还有思路

解决方案 »

  1.   

    如果用集合类 比较简单
    将你数组元素逐个放入 hashset中,如何在根据Collections。sort()实现自己的排序规则的比较接口
    就可以了。。
      

  2.   

    什么类型的数组?int?char?String?
      

  3.   

    去重复就直接丢到Set中去好了,然后再排序。
      

  4.   


            List list = new ArrayList();
            List list1 = new ArrayList();
            list.add("a");
            list.add("b");
            list.add("b");
            list.add("e");
            list.add("i");
            list.add("v");
            list.add("p"); 
            list.add("a");
            list.add("b");
            list.add("b");
            list.add("e");
            list.add("i");
            list.add("v");
            list.add("p"); 
            Set set = new HashSet();
            
            set.addAll(list);
            
            
            for(java.util.Iterator it = set.iterator(); it.hasNext(); )
            {
                list1.add(it.next());
            }
            java.util.Collections.sort(list1);
            System.out.println(list1);运行结果:[a, b, e, i, p, v]
      

  5.   

    额,直接扔进TreeSet,有必要的话自己写好Comparator,然后再转出来……public static void main(String[] args) {
    int[] src = { 49, 38, 65, 97, 76, 13, 27, 38, 13 };
    Set<Integer> set = new TreeSet<Integer>();
    for (int i : src) {
    set.add(i);
    }
    int[] dest = new int[set.size()];
    Iterator<Integer> iter = set.iterator();
    for (int i = 0; i < dest.length && iter.hasNext(); i++) {
    dest[i] = iter.next();
    }
    System.out.println(Arrays.toString(dest));
    }输出结果:
    [13, 27, 38, 49, 65, 76, 97]
      

  6.   

    to: 楼上,treeset效率非常低,没加一个元素 要排序依次,,,如果数据多的话
    发狂 ing
      

  7.   

    int i[]=new int[]{1,2};
    Set set=new TreeSet(Arrays.asList(i));
    排序加去重都可以了
      

  8.   


    似乎要写成
    Integer i[] = new Integer[]{1, 2};
    才行的吧?
      

  9.   


    public class TestRepeat
    {    /**
         * @param args
         */
        public static void main(String[] args)
        {        String[] str = { "a", "e", "ee", "rr", "ce", "love", "you", "am", "sb", "bs", "jj", "gg", "mm", "love", "a",
                    "e", "tt", "yy" };//定义一个数组
           
            List list = new ArrayList();//new一个arralist
            Set set = new HashSet();//new 一个hashset
            set.addAll(java.util.Arrays.asList(str));//将数组转为list并存入set中,就可以去掉重复项了
            for (java.util.Iterator it = set.iterator(); it.hasNext();)
            {
                list.add(it.next());//遍历set 将所有元素键入list中
            }
            java.util.Collections.sort(list); //对list进行快速排序
            System.out.println(list);//打印结果    }结果:[a, am, bs, ce, e, ee, gg, jj, love, mm, rr, sb, tt, you, yy]
      

  10.   

    先放到Set中,除去重复,同去取出排序
      

  11.   

    只用数组的话实现是没有问题的,但是很麻烦……因为数组无法改变大小的…… int[] src = { 49, 38, 65, 97, 76, 13, 27, 38, 13 };
    int[] temp = new int[src.length];
    int count = 0;
    for (int i = 0; i < src.length; i++) {
    temp[count] = src[i];
    for (int j = 0; j < count; j++) {
    if (temp[j] == temp[count]) {
    count--;
    break;
    }
    if (temp[j] > temp[count]) {
    temp[count] = temp[j] ^ temp[count];
    temp[j] = temp[j] ^ temp[count];
    temp[count] = temp[j] ^ temp[count];
    }
    }
    count++;
    }
    int[] dest = new int[count];
    System.arraycopy(temp, 0, dest, 0, count);
    System.out.println(Arrays.toString(dest));尝试写注释……觉得写不出东西……
      

  12.   

    上面是插入时直接去排序,也可以利用Arrays.sort排序 int[] src = { 49, 76, 38, 13, 27, 38, 65, 97, 13 };
    int[] temp = new int[src.length];
    int count = 0;
    for (int i = 0; i < src.length; i++) {
    temp[count] = src[i];
    for (int j = 0; j < count; j++) {
    if (temp[j] == temp[count]) {
    count--;
    break;
    }
    }
    count++;
    }
    int[] dest = new int[count];
    System.arraycopy(temp, 0, dest, 0, count);
    Arrays.sort(dest);
    System.out.println(Arrays.toString(dest));
      

  13.   

    import java.util.*;public class TestRepeat {
    public static void main(String[] args) {
    String[] str = { "a", "e", "ee", "rr", "ce", "love", "you", "am", "sb",
    "bs", "jj", "gg", "mm", "love", "a", "e", "tt", "yy" }; List list = new ArrayList();
    Set set = new TreeSet();
    set.addAll(java.util.Arrays.asList(str));
    System.out.println(set);
    }
    }
      

  14.   

     temp[count]= temp[j]^ temp[count];这是什么意思
      

  15.   


    ^表示异或,这是一种用来交换数组中两个数的方法,当然你也可以这么写
    int n = temp[count];
    temp[count] = temp[j];
    temp[j] = n;
    达到的效果是一样的
    就是注意和本身交换的话需要作处理,要判断一下跳过
    因为这个问题不会出现这种情况,所以就这样无所谓了
      

  16.   

    System.out.println(Arrays.toString(dest));
    会报错耶,说“类型 Object 中的方法 toString()对于参数(int[])不适用”。
      

  17.   

    先放入set,然后排序
    即先去重复,后排序
      

  18.   

    直接用CollectionUtils(setvalue,arrayvalue); OK