怎么去掉(int 或 double不能是字符数组)数组中的重复元素?
比如说int[] a={23,10,5,10,3,5,9,6,7,3}
怎么处理才能去掉s中的重复元素,实现这样的效果int[] a={23,5,9,6,7}

解决方案 »

  1.   

    use a heap or a set
      

  2.   

    Set set = new HashSet();
    for(int i=0;i<a.length;i++)
    {
       set.add(a[i]);
    }set里面就是你要的,在转成树组就可以了
      

  3.   

    如果要保持原有的顺序,使用LinkedHashSet代码同楼上最后,toArray()就可以了
      

  4.   

    LinkedHashSet这是个什么?hash集合
      

  5.   

    int[] a = {23,10,5,10,3,5,9,6,7,3};
    int[] b = new int[10];
    boolean tag = false;
    int bi = 0;
    for (int i = 0; i < a.length; i++)
    {
    for (int j = 0; j < b.length; j++)
    {
    if(b[j] == a[i])
    {
    tag = true;
    //bi = j;
    break;
    }
    }
    if(tag == false)
    {
    b[bi] = a[i];
    bi++;
    }
    tag = false;
    }
    for(int i = 0; i < b.length; i++)
    {
    System.out.println(b[i]);
    }
      

  6.   

    result:
    23
    10
    5
    3
    9
    6
    7
    0
    0
    0
      

  7.   

    import java.util.*;public class Test1
    {
    public static void main(String[] args)
    {
    int[] a={23,10,5,10,3,5,9,6,7,3};
    Map m=new HashMap();
    for(int i=0;i<a.length;i++)
    m.put(a[i],"3");
    System.out.println(m.keySet());
    }
    }但估计性能不会很好!!!
      

  8.   

    use a heap or a set同意!!!
      

  9.   

    Set set=new hashSet();
    for(int i =0;i<a.size();i++){
     set.add(a[i])
    }