title: How to convert a string with "[]" into an integer array
body: <p>I have two strings:</p>
  
  <pre><code>String s1 = "[143, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 157, 158, 159, 162, 163, 164]";
  
  String s2 = "[20, 35, 74, 78, 124, 125, 126, 127, 131, 132, 143, 144, 145, 146]";
  </code></pre>
  
  <p>All I want to do is find the smallest common number in this two strings. So I first displace the "[]" symbol, and extract numbers from string into integers. Then use a loop to find the smallest common number.The program is as below:</p>
  
  <pre><code>s1 = s1.replace("[",""); 
  s1 = s1.replace("]","");
  String [] band = s1.split(",");     
  s2 = s2.replace("[",""); 
  s2 = s2.replace("]","");
  String [] hotel = s1.split(",");    
  System.out.println( EarliestCommonSlot(hotel,band) );
  </code></pre>
  
  <p>The EarliestCommonSlot() is defined as below:</p>
  
  <pre><code>public static int EarliestCommonSlot(String [] a1, String [] b1){
      int i=0,j=0;
      int common = -1;
      int [] a = new int [a1.length];
      int [] b = new int [b1.length];
  
      for(i = 0;i &lt; a1.length;i++)
      {
          a[i] = Integer.parseInt( a1[i]);
          System.out.println(a1[i]);
      }
      for(i = 0;i &lt; b1.length;i++)
      {
          b[i] = Integer.parseInt( b1[i]);
          System.out.println(b1[i]);
      }
      i = 0; j=0;
      while ( i&lt; a.length &amp;&amp; j &lt; b.length){
          if ( a[i] == b[j] ){
              common = a[i]; break;
          }
          if ( a[i] &lt; b[j] ){
              i++;
          }
          else j++;
      }
      return common;
  }
  </code></pre>
  
  <p>But when I run the program, it has the following error:</p>
  
  <pre><code>Exception in thread "main" java.lang.NumberFormatException: For input string: " 143"
      at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
      at java.lang.Integer.parseInt(Integer.java:481)
      at java.lang.Integer.parseInt(Integer.java:527)
      at ClientReserve.EarliestCommonSlot(ClientReserve.java:39)
      at ClientReserve.main(ClientReserve.java:179)
  </code></pre>
  
  <p>Why is that? How could I fix that?</p>