title: Only printing the first element of a 2D array with repeating values in first column
body: <p>I have a 2D array that looks like this.</p>
  
  <blockquote>
    <p>10002,20<br/>
    10004,72<br/>
    10008,12<br/>
    10010,37<br/>
    10010,34<br/>
    10007,28<br/>
    20003,42<br/>
    20003,38<br/>
    10002,16<br/></p>
  </blockquote>
  
  <p>As you can see, it has some repeating numbers in the first column such as 10010 and 20003, and I only want to print out the first one of each that pops up. So that means I want the println to print out</p>
  
  <blockquote>
    <p>10002,20<br/>
    10004,72<br/>
    10008,12<br/>
    10010,37<br/>
    10007,28<br/>
    20003,42<br/>
    end</p>
  </blockquote>
  
  <p>(KEY NOTE:The first element that pops up with repeating numbers in the first column will always have the largest int in the second column, EX: 10010,37>34 and 20003,42>38 ALWAYS.)
  but I'm not sure how to do so... </p>
  
  <p><strong>Edit: Here is the full code with a snippet of the XLS file</strong></p>
  
  <pre><code>import java.io.FileInputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.util.*;
  
  import org.apache.poi.hssf.usermodel.HSSFCell;
  import org.apache.poi.hssf.usermodel.HSSFSheet;
  import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  
  public class Read {
  
              public static void readXLSFile() throws IOException{
          InputStream ExcelFile = new FileInputStream("C:/Sales Data.xls");
          HSSFWorkbook wb = new HSSFWorkbook(ExcelFile);
                  HSSFSheet sheet=wb.getSheetAt(0);
  
                  int numRows = sheet.getPhysicalNumberOfRows(); 
                  int[][] idSale = new int[numRows][2];
  
                  for(int i=1;i&lt;numRows;i++){
                      HSSFCell proId = sheet.getRow(i).getCell(1);
                      HSSFCell sales = sheet.getRow(i).getCell(2);
                      idSale[i][0]=(int)proId.getNumericCellValue();
                      idSale[i][1]=(int)sales.getNumericCellValue();
                  }
                  for(int j=1;j&lt;numRows;j++){
                      for(int jj=j+1;jj&lt;numRows;jj++)
                          if(idSale[j][0]==idSale[jj][0]){
                             idSale[j][1]+=idSale[jj][1];
  //the problem with this loop is that there are repeated numbers in 
  //the first column as I'm comparing the entire array to a copy of itself
  //and I'm not sure how to avoid it...
                          }
                  }
              }
  
  
  
              public static void main(String[] args) throws IOException {
          readXLSFile();
              }
  }
  </code></pre>
  
  <p>This is a snippet of the XLS file I'm reading off of.
  <a href="http://postimg.org/image/drbq7fucz/" rel="nofollow">http://postimg.org/image/drbq7fucz/</a>
  This program is meant to be flexible and be used on excel files with the same format. Basically the assignment is to add the units of matching product ID's and then spit them back out afterwards in a row/column format. Customer ID is irrelevant. I can't preset array size because the program must be able to read different excel files that may have different numbers of rows...</p>