title: how to convert an integer string separated by space into an array in JAVA
body: <p>Suppose I have a string "1 23 40 187 298". This string only contains integers and spaces. How can I convert this string to an integer array, which is [1,23,40,187,298].
  this is how I tried</p>
  
  <pre><code>public static void main(String[] args) {
      String numbers = "12 1 890 65";
      String temp = new String();
      int[] ary = new int[4];
      int j=0;
      for (int i=0;i&lt;numbers.length();i++)
      {
  
          if (numbers.charAt(i)!=' ')
              temp+=numbers.charAt(i);
          if (numbers.charAt(i)==' '){
              ary[j]=Integer.parseInt(temp);
              j++;
          }
      }
  }
  </code></pre>
  
  <p>but it doesn't work, please offer some help. Thank you!</p>