title: Removing all spaces in an ArrayList. Java
body: <p>I am taking input from a .txt file and storing it into an ArrayList. I need to get rid of all the spaces so I can parse the <code>ArrayList</code> to an <code>&lt;Integer&gt;</code>. I am going to post commented out sections so you can see what i have tried to use to do this. Thank you. If you can give me somewhere to look that would be great.</p>
  
  <pre><code>import java.io.*;
  import java.util.*;
  
  public class LabWriterReadre {
  
    public static void main(String [] args){
         BufferedReader br = null;
         BufferedWriter bw = null;
        // fileWriter = new FileWriter("output.txt",false);
         ArrayList&lt;String&gt; storage = new ArrayList&lt;String&gt;();
         ArrayList&lt;String&gt; convertToInt = new ArrayList&lt;String&gt;();
         ArrayList&lt;Integer&gt; matrix = new ArrayList&lt;Integer&gt;();
           String strLine = "";
          int row1,col1,row2,col2; 
  
          try {
              br = new BufferedReader( new FileReader("C:/Users/jeremiahlukus/Desktop/New folder/jj.txt"));
              while( (strLine = br.readLine()) != null)
              {
                  System.out.println(strLine);
                  storage.add(strLine);             
              }
          } catch (FileNotFoundException e) {
              System.err.println("Unable to find the file: fileName");
          } catch (IOException e) {
              System.err.println("Unable to read the file: fileName");
          }
  
  
          /*
          String[] trimmedArray = new String[string.size()];
          for (int i = 0; i &lt; string.size(); i++)
          {
              trimmedArray[i] = string[i].trim();
              string.removeAll(Arrays.asList(null,""));
          }
          */
          //string.removeAll(Collections.singleton(""));
         // string.removeAll(Arrays.asList(null,"")
  
        for (String str : storage)
        {
           if (//str != " ")
               !str.isEmpty())
           {
            convertToInt.add(str);
            //convertToInt.trim();
  
           }
       }
  
  System.out.println(convertToInt);
  }
  
   /* 
  
         row1 = Integer.parseInt(convertToInt.get(0));
         col1 = Integer.parseInt(convertToInt.get(1));
         row2 = Integer.parseInt(convertToInt.get(2));
         col2 = Integer.parseInt(convertToInt.get(3));
  
         int[][] matrix1=new int[row1][col1];
         int[][] matrix2=new int[row2][col2];
  
       */  
  
        //  System.out.println(row1);
  
  
          /*
  </code></pre>
  
  <p>This is the .txt file I am reading, <code>_</code> means space </p>
  
  <pre><code>3___________3
  3_4
  
  1 ______2 3 
  4_5 _6
  7 _8 _9
  
  1 _2_ 3_ 4
  5 _6 _7 _8
  9_ 10_ 11_ 12
  </code></pre>
  
  <p>This is the ArrayList printed out </p>
  
  <pre><code>[3______3,_3 _4,__ 1_______2_ 3 , ___4 _5 _6, 7_ 8 _9, 1_ 2_ 3_ 4, 5 _6_ 7_ 8, 9 _10_ 11_ 12]
  </code></pre>
  
  <p>This is what I want to happen</p>
  
  <pre><code>[3,3,3,4,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,10,11,12]
  </code></pre>