title: Iterating over a sorted array to remove duplicates
body: <p>Let me start by saying this a homework question that I am having trouble with.</p>
  
  <p>I have sorted an array and what I need to do is use another array to remove duplicates by iterating over the first and comparing adjacent items then adding the non duplicates to the new array.  Once I have finished that I set the old array = to the new array.  I am not used to java and therefore I am running into some problems I think getting the iteration setup correctly.  </p>
  
  <pre><code>public static void main(String[] args) {
      args = new String[] { "data/list1.txt" };
      StdIn.fromFile("data/list2.txt");
      // StdOut.toFile ("finished.txt");
      int[] whitelist = In.readInts(args[0]);
  
      Arrays.sort(whitelist);
      int newArray[] = new int[whitelist.length];
      for (int i = 0; i &lt; whitelist.length-1; i++) {
          int k = 0;
          if(whitelist[i+1] &gt; whitelist[i])
              newArray[k] = whitelist[i];
              k++;
          StdOut.println(java.util.Arrays.toString(whitelist));
          whitelist = newArray;
          }
      for (int i=0; i&lt;newArray.length;i++){
          StdOut.println(java.util.Arrays.toString(newArray));
      }
  </code></pre>
  
  <p>This code piece is part of a larger binary search, but this is the portion I am having problems with.  </p>
  
  <p>My output besides not having the duplicates removed also prints out several times.</p>
  
  <p>Any direction would be greatly appreciated.</p>