title: Efficient way to group data in a large file using Java
body: <p>Consider a file of the following format containing <strong>n</strong> number of records &amp; <strong>i</strong> number of columns. If data needs to be grouped by the first column, what is the efficient way to process it using Java? Let's say that <strong><em>n = 40 million</em></strong>. </p>
  
  <p>The standard way could be using BufferedReader to loop through each line and organized the data in a map with <em>Column A</em> as the key. Is there a more efficient &amp; optimal way?</p>
  
  <pre><code>A1~1~2
  A1~2~5
  A2~1~3
  A1~3~4
  ....
  ....
  </code></pre>
  
  <p>The above file needs to be organized to Map of ColumnA &amp; a POJO as below. </p>
  
  <pre><code>A1 [(1,2),(2,5),(3,4)]
  A2 [(1,3)]
  </code></pre>