title: Removing the smallest 2 elements in an arraylist in java?
body: <p>I have an arraylist of integers, i need to compute the average of the integers excluding the smallest two integers. I keep trying different ways of doing this but think what I want to do is find min1, remove it and then find min2 then remove that. </p>
  
  <pre><code>public double computeAverageWithoutLowest2()
    {
      ArrayList&lt;Student&gt; newscores = new ArrayList&lt;Student&gt;(scores);
      int newtotalScores=0;
      int newavg=0; 
      int min1 = 0;
      int min2 = 0;
  
      min1 = newscores.get(0).getScore();
  
      for (int i = 0; i&lt; newscores.size(); i++)
      {
        if (newscores.get(i).getScore() &lt; min1)
        {
          min1 = newscores.get(i).getScore();
        }
      }
  </code></pre>
  
  <p>now I want to remove min1 from my arraylist. I have obviously tried newscores.remove(min1); which does not work. How can I figure out what spot in the array min1 is and then delete it?</p>
  
  <p>Any help would be great thanks!!</p>
  
  <p>Alright so now after looking at the comments I changed my code to:</p>
  
  <pre><code>ArrayList&lt;Student&gt; newscores = new ArrayList&lt;Student&gt;(scores);
      int newtotalScores=0;
      int newavg=0; 
  
      int minPos1 = 0;
      int minPos2 = 0;
      int min1 = newscores.get(0).getScore();
      int min2 = newscores.get(0).getScore();
  
      for(int i = 0; i &lt; newscores.size(); i++) 
      {
        if(newscores.get(i).getScore() &lt; min1) 
        {
          min1 = scores.get(i).getScore();
          minPos1 = i;
        } 
      }
      newscores.remove(minPos1);
  
  
      for(int j = 0; j &lt; newscores.size(); j++)
      {
        if(newscores.get(j).getScore() &lt; min2)
        {
          min2 = scores.get(j).getScore();
          minPos2 = j;
        }
      }
      newscores.remove(minPos2);
  </code></pre>
  
  <p>This way works to remove min1, but does not work to remove min2 instead it just removes the same position that min1 removed. </p>