Question: hey guys,
 right i have an array of 50 random integers and i have to check if any of them are the same,
here is my code so far it only checks ajacent indexs

```
for (int i =0; i < 50; i++)
{
    System.out.print("Student" + i + ": "   );

    customers[i] = (int)((Math.random()*10000)%10+1);
    System.out.print(" " +customers[i]+ "\n");

    if( duplicate == customers[i])
    {
        System.out.println("yup");
    }
    duplicate = customers[i];
}

```

Answer: 
You could use `Arrays.sort` (see more at <http://www.exampledepot.com/egs/java.util/coll_SortArray.html>) to sort your data, and then check for duplicates.
You can use the below code if you are working with Integer array:

```
public class DuplicateInteger {

    private static int countDuplicate;

    public static int[] getDuplicateIntegers(int[] integerArray){
        int duplicateIntegers[] = new int[integerArray.length];
        countDuplicate = 0;
        for(int i=0;i<integerArray.length;i++){
            for(int j=i+1;j<integerArray.length;j++){
                int replicaTest = 0;
                if(integerArray[i]==integerArray[j]){
                    for(int k=0;k<countDuplicate;k++){
                        if(duplicateIntegers[k]==integerArray[i]){
                            replicaTest = 1;
                        }
                    }
                    if(replicaTest==0){
                        duplicateIntegers[countDuplicate] = integerArray[i];
                        countDuplicate++;
                    }
                }
            }
        }
        return duplicateIntegers;
    }

    public static void printDuplicateIntegers(int[] duplicateIntegers){
        System.out.println("Duplicate Integers:");
        System.out.println("-------------------");
        for(int i=0;i<countDuplicate;i++){
            System.out.println(duplicateIntegers[i]);
        }   
    }

    public static void main(String[] args){
        int numberArray[] = {1, 2, 3, 4, 5, 6, 7, 1, 3, 5, 7};
        printDuplicateIntegers(getDuplicateIntegers(numberArray));
    }

}

```