Checking an array for duplicate values This function checks an array for duplicated values. If it finds a duplicate value, it increments the variable name repeatedTime and then if repeatedTime is greater than 1 it calls a randomize function which produce different values in the array that was passed to the function. It repeats these steps until a duplicated value free array is produced and then notDuplicate becomes true and the function ends. 

Are there any improvements that can be made to the function? I am thinking about making it into a recursive function. Is that feasible?

private void CheckForDuplicates(int[] selectedWordIds, List&lt;Integer&gt; answersTempId) {
    boolean notDuplicate = false;

    while(notDuplicate != true){
        int repeatedTime = 0;
        for(int x = 0; x &lt; selectedWordIds.length ; x++)
        {
            for(int y =0; x &lt; selectedWordIds.length;x++)
            {
                if(selectedWordIds[x] == selectedWordIds[y])
                {
                    repeatedTime++;
                }
            }
        }
      if(repeatedTime &gt; 1)
      {
          notDuplicate = false;
          RandomizeFunction(selectedWordIds, answersTempId);
      }
      else{
          notDuplicate    = true;
      }
    }
}
I suggest you use a Set when checking for duplicates:

Set&lt;Integer&gt; set = new HashSet&lt;&gt;();

for(int i : selectedWordIds) {
    if(!set.add(i)) {
        repeatedTime++;
    }
}


This is much simpler that what you have.

Here:


 if(repeatedTime &gt; 1)
 {
     notDuplicate = false;
     RandomizeFunction(selectedWordIds, answersTempId);
 }



The assignment notDuplicate = false is not necessary because notDuplicate is already false.

About recursion: It is possible. With it, here is the final code:

private void CheckForDuplicates(int[] selectedWordIds,
        List&lt;Integer&gt; answersTempId) {

    int repeatedTime = 0;

    Set&lt;Integer&gt; set = new HashSet&lt;&gt;();

    for(int i : selectedWordIds) {
        if(!set.add(i)) {
            repeatedTime++;
        }
    }
    if (repeatedTime &gt; 1) {
        RandomizeFunction(selectedWordIds, answersTempId);
        CheckForDuplicates(selectedWordIds, answersTempId);
    }

}