日期:2014-05-20  浏览次数:20657 次

查找数组中重复数据索引
有这样一个数组
String[]   arr   =   {10,20,45,20,10,50,50};
然后查找出重复数据的索引号
结果   0,1,3,4,5,6



------解决方案--------------------
Java code

int[] arr = {10,20,45,20,10,50,50};  
        for(int i=0;i<arr.length;i++)
        {
            int tmp =arr[i];
            for(int j=i+1;j<arr.length;j++)
            {
                if(arr[j]==tmp)
                {
                    System.out.println(i);
                    System.out.println(j);
                    break;
                }
            }
        }

------解决方案--------------------
Java code
String[]   arr   =   {"10","20","45","20","10","50","50"};
        int count = 0;
        System.out.println("重复数据索引:");
        for(int i = 0; i < arr.length; i++){
            
            for(int j = 0; j < arr.length; j++){
                
                if(arr[i] == arr[j]){
                    
                    count++;
                }
                
            }
            
            if(count > 1){
                
                System.out.println(i);
                count = 0;
            }
        }