Java - Is there anyway I can prevent duplicates in an array without using an ArrayList?
<p>I'm trying to create a code to prevent duplicate array elements. Is there anyway I can do this without creating an arrayList?</p>

<p>When running the program this error occurs when I enter the first #: </p>

<p>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
    at DuplicateElimination.main(DuplicateElimination.java:32)</p>

<p>Here is my code:</p>

<pre><code>int[] numList = new int[5];
int newValue;
boolean invalid;

for (int i = 0; i &lt; numList.length; i++){
    do{
        System.out.print("Please enter number");
        System.out.println(" ");
        newValue = input.nextInt();

        //This is where the error occurs when I try to compare
        //The last list element to the input value
        invalid = numList[i-1] == newValue;

        if(newValue &lt; 10 || newValue &gt; 100){
            System.out.print("Invalid number, Please enter a number between 10 and 100");
            newValue = input.nextInt();
        }
        if(invalid){
            System.out.print("That number was entered already try again");
        }
    }while(invalid);

    insertIntoArray(numList, i, newValue);
    printArray(numList);
}
</code></pre>