title: Read Tab-Separated-Columns into Lists - Java
body: <p>Tab-Separated File: </p>
  
  <pre><code>2019-06-06 10:00:00 1.0
  2019-06-06 11:00:00     2.0
  </code></pre>
  
  <p>I'd like to iterate over the file once and add the value of each column to a list.</p>
  
  <p>My working approach would be:</p>
  
  <pre><code>import java.util.*;
  import java.io.*;
  
  public class Program {
  public static void main(String[] args) 
  {
  ArrayList&lt;Double&gt; List_1 = new ArrayList&lt;Double&gt;();
  ArrayList&lt;Double&gt; List_2 = new ArrayList&lt;Double&gt;();
  
  String[] values = null;
  String fileName = "File.txt";
  File file = new File(fileName);
  try
      {
      Scanner inputStream = new Scanner(file);
      while (inputStream.hasNextLine()){
          try {
          String data = inputStream.nextLine();
          values = data.split("\\t");
          if (values[1] != null &amp;&amp; !values[1].isEmpty() == true) {
              double val_1 = Double.parseDouble(values[1]);
              List_1.add(val_1);
              }
          if (values[2] != null &amp;&amp; !values[2].isEmpty() == true) {
              double val_2 = Double.parseDouble(values[2]);
              List_2.add(val_2);
              }
          }
          catch (ArrayIndexOutOfBoundsException exception){   
          }
          }
          inputStream.close();
          }
  catch (FileNotFoundException e) {
      e.printStackTrace();
  }
  System.out.println(List_1);
  System.out.println(List_2);
  }
  }
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>[1.0]
  [2.0]
  </code></pre>
  
  <p>It doesn't work without the checks for <code>null</code>, <code>ìsEmpty</code> and the <code>ArrayIndexOutOfBoundsException</code>. </p>
  
  <p>I would appreciate any hints on how to save a few lines while keeping the scanner approach.</p>