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: 
Sort the array first. Then you can check just the next index. If it's ever the same, break.

---

Okay, I hate ridiculous limitations. If you want, you can do it like this without using a sort:

```
import java.util.ArrayList;
import java.lang.Math;

public class Main {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<Integer>();
        Integer currentValue = 0;

        int i = 0;
        int limit = 20;

        for(i = 0; i < limit; i++) {
            list.add((int)(Math.random() * 100));            
        }      

        for(i = 0; i < limit; i++) {
            currentValue = list.get(i);
            list.set(i, -1);
            if(list.contains(currentValue)) {
                System.out.println("yup:" + currentValue);
                return;
            } else {
                list.set(i, currentValue);
            }
        }

        System.out.println("No duplicates!");
        return;
    }
}

```

Is it efficient? No.

Does it work? Yes.
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.