title: how to have an array list save only the first occurence of a number of a number that appears multiple times in a text list?
body: <p>I am a beginner in java so please go easy. I am trying to read a file, and save only the first occurrence of recurring numbers that appear in the file into an ArrayList.</p>
  
  <p>This is what I have so far:</p>
  
  <pre><code>import java.io.*;
  import java.util.Scanner;
  
  public class ListReader
  {
    File numbers = new File("numbers.txt");
    //numbers.txt has numbers {26, 26, 44, 9, 64, 7, 19, 11, 80, 9}
    Scanner in = new Scanner(numbers);
    ArrayList&lt;Integer&gt; nums = new ArrayList&lt;Integer&gt;();
    while(in.hasNextInt())
    {
       nums.add(in.nextInt());
    } 
    int j = nums.size() - 2;
    for(int i = nums.size() - 1; i &gt;= 0; i--)
    {
       if(nums.get(i) == nums.get(j))
       {
         nums.remove(nums.get(i)));
         j--;
       }
       else
       {
         j--;
       }
    }
    System.out.println(nums);
  }
  </code></pre>
  
  <p>Every time I run the code, I get an index out of bounds error, which I do not know how to avoid. If the out of bounds error is corrected, will this successfully get rid of the extra 26 and 9?</p>