title: How can I split a string in to multiple parts?
body: <p>I have a string with several words separated by spaces, e.g. "firstword second third", and an ArrayList. I want to split the string into several pieces, and add the 'piece' strings to the ArrayList. </p>
  
  <p>For example,"firstword second third" can be split to three separate strings , so the ArrayList would have 3 elements; "1 2 3 4" can be split into 4 strings, in 4 elements of the ArrayList. See the code below:</p>
  
  <pre><code>public void separateAndAdd(String notseparated) {
      for(int i=0;i&lt;canBeSepartedinto(notseparated);i++{
      //what should i put here in order to split the string via spaces?
          thearray.add(separatedstring);
      }
  }
  
  public int canBeSeparatedinto(String string)
      //what do i put here to find out the amount of spaces inside the string? 
      return ....
  }
  </code></pre>
  
  <p>Please leave a comment if you dont get what I mean or I should fix some errors in this post. Thanks for your time! </p>