title: NumberFormatException: For input string: "2"
body: <p>I have a list of strings. First element is:</p>
  
  <pre><code>2       helloworld                    10173.991234
  </code></pre>
  
  <p>I've written the code below:</p>
  
  <pre><code>            ArrayList&lt;Integer&gt; idList = new ArrayList&lt;Integer&gt;();
              for (String s:list){
                  String subs = s.substring(0,8);
                  subs = subs.trim();
                  idList.add(Integer.valueOf(subs));
              }
  </code></pre>
  
  <p>This code shoud parse first <code>id</code> field and add it to arraylist.
  But it fails on line <code>idList.add(Integer.valueOf(subs));</code></p>
  
  <p>Whats the problem? Any help?</p>
  
  <p>Upd:</p>
  
  <pre><code>public class Solution {
      public static void main(String[] args) throws Exception {
          if (args[0].equals("-c")) {
              BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
              String fileString = reader.readLine();
              reader.close();
              Scanner scanner = new Scanner(new File(fileString));
              ArrayList&lt;String&gt; list = new ArrayList&lt;String&gt;();
              while (scanner.hasNextLine()) {
                  list.add(scanner.nextLine());
              }
              String ne = list.get(list.size()-1);
              scanner.close();
              int maxId;
              if (ne.length()&gt;1) {
                  ArrayList&lt;Integer&gt; idList = new ArrayList&lt;Integer&gt;();
                  for (String s:list){
                      String subs = s.substring(0,8);
                      subs = subs.trim();
                      idList.add(Integer.parseInt(subs));
                  }
                  maxId = idList.get(0);
                  for (int i:idList){
                      if (maxId&lt;i){
                          maxId=i;
                      }
                  }
                  maxId++;
              }
              else {
                  maxId = 0;
              }
              String maxIdString = ""+maxId;
              while (maxIdString.length()&lt;8){
                  maxIdString+=" ";
              }
              if (maxIdString.length()&gt;8){
                  maxIdString = maxIdString.substring(0,8);
              }
              String productName = "";
              for (int i = 1; i &lt; args.length-2; i++) {
                  productName+=args[i]+" ";
              }
              productName = productName.trim();
              while (productName.length()&lt;30){
                  productName+=" ";
              }
              if (productName.length()&gt;30)
                  productName=productName.substring(0,30);
              String price = args[args.length-2];
              while (price.length()&lt;8){
                  price+=" ";
              }
              if (price.length()&gt;8)
                  price=price.substring(0,8);
              String quantity = args[args.length-1];
              while (quantity.length()&lt;4){
                  quantity+=" ";
              }
              if (quantity.length()&gt;4)
                  quantity=quantity.substring(0,4);
              String outString = maxIdString+productName+price+quantity;
              FileOutputStream outputStream = new FileOutputStream(fileString,true);
              if (ne.length()&gt;1)
                  outputStream.write("\r\n".getBytes());
              outputStream.write(outString.getBytes());
              outputStream.close();
          }
      }
  }
  </code></pre>
  
  <p>It's the content of the file</p>
  
  <pre><code>2       helloworld                    10173.991234
  124     helloworld                    10173.991234
  125     helloworld                    10173.991234
  </code></pre>
  
  <p>Program arguments, for example:</p>
  
  <pre><code>-c helloworld 10173.99 1234
  </code></pre>