title: How do you remove duplicates from an array?
body: <p>I am trying to make is so that in the method populate as the populate array increases it checks the index above if the value is the same. However, I have no idea how to do it without going through each index individually making it super inefficient. I tried to make a for loop where the I value is 0 and increases by 1 and inside that for loop is another for loop with the b value is 1 and that also increases by 1. Inside the second for loop I have an if statement and if the I index is equal to the b index the I index is revalued again</p>
  
  <pre><code>public class CH7Ass {
  
      public static void main(String[] args) {
          int user;
          int[] array;
          int checkUserNum;
          int tries=0;
          System.out.println("I bet you can't guess my six numbers");     
          array=populate();
          do{
              tries++;
              user=getUserNum();
              checkUserNum=checkUserNum(user,array);
              array=removeFromArray(array,checkUserNum);
          }while(tries&lt;6);
      }
  
      public static int[] populate(){
          int[] populate;
          populate= new int [6];
          int random;
  
          for(int i=0;i&lt;populate.length;i++){
              random=(int) ((Math.random())*50);      //goes from 0-49
              populate[i]=random;
              System.out.println(populate[i]);
              for(int b=1;b&lt;populate.length;b++){
                  if(populate[b]==populate[i]){
                      populate[i]=random;
                  }
              }
          }
          return  populate;
      }
  
  
      public static int getUserNum(){
          int getUserNum;
  
          do{
              System.out.println("Please input a number from 1 to 49:");
              getUserNum=TextIO.getInt();
          }while((getUserNum&lt;1)||(getUserNum&gt;49));
  
          return getUserNum;
      }
  
      public static int checkUserNum(int getUserNum,int[] array){
          boolean check=false;
          int checkUserNum = 0;
          for(int i=0;i&lt;array.length;i++){
              if(array[i]==getUserNum){
                  check=true;
                  System.out.println("You got it");
                  checkUserNum=i;
              }
          }
          if(check==false){
              checkUserNum=-1;
              System.out.println(checkUserNum);
          }
  
          return checkUserNum;
      }
  
  
      private static int[] removeFromArray(int[] array,int checkUserNum){
          int[] removeFromArray;
          if(checkUserNum!=-1){
              array[checkUserNum]=0;
              removeFromArray=array[checkUserNum];
          }
          return removeFromArray;
      }
  }
  </code></pre>