title: Efficient Algorithm for reading data from Excel Spreadsheet in Java
body: <p>I'm working on a little project that reads party (aka client) data from a spreadsheet into two hashmaps. One keeps track of each party with the value being the object Party, the other is embedded in the Party Object that keeps track of each party's data. Thing is, the way I'm doing it is with two for-loops, which as we all know is a O(N^2) algorithm. The way it is now is about 500 rows (or 500 parties) with about 65 columns (or 65 labels/values) so at that number of elements it's not really a big deal. However, I've been told it might have to handle over 25 million rows, in which case O(N^2) is a problem (not technically O(N^2) with the columns I guess, but the number of columns could be expanded it's not necessarily set at 65). </p>
  
  <p>Long story short, I need tips on how to reduce the run-time but I can't really think of any other way to access every cell in the sheet.</p>
  
  <p>Here's the relevant code:</p>
  
  <pre><code>package storage;
  
  import java.io.File;
  import java.util.HashMap;
  
  
  import jxl.Sheet;
  import jxl.Workbook;
  
  import pojo.Party;
  
  public class PartyStructure {
  
      private static HashMap&lt;String, Party&gt; map;
      private static PartyStructure partyStructure;
      private String inputFile = "C:/Users/joayers/Documents/API Project Information/Sample Data.xls";
      File excelData = new File(inputFile);
  
      private PartyStructure() throws Exception
      {
          map = new HashMap&lt;String, Party&gt;();
          readData();
      }
  
      public static HashMap&lt;String,Party&gt; getPartyCollection() throws Exception
      {
          if(partyStructure==null)
          {
              partyStructure = new PartyStructure();
          }
          return map;
      }
      private void readData() throws Exception 
      {
          Workbook w=Workbook.getWorkbook(excelData);
          Sheet sheet = w.getSheet(0);
          String party_name;
          String labelName;
          String dataField;
  
          for(int i=1;i&lt;sheet.getRows();i++)
          {
              party_name = sheet.getCell(2, i).getContents().toString();
              //map is a Hashmap&lt;String, Party&gt; 
              map.put(party_name, new Party());
  
                  for(int j=0;j&lt;sheet.getColumns();j++)
                  {
                      labelName = sheet.getCell(j, 0).getContents().toString();
                      dataField = sheet.getCell(j, i).getContents().toString();
                      Party party = map.get(party_name);
                      //getPartyInfo is a getter for a HashMap&lt;String, String&gt; that holds values associated with the keys (the labels in excel)
                      party.getPartyInfo().put(labelName, dataField);
                  }
          }   
      }
  
  }
  </code></pre>
  
  <p>Also, is there any difference between a hashmap and a hashtable? They seem like the same thing </p>