title: Read String Until Space Then Split - Java
body: <p>How can I split a string in Java?<br>
  I would like to read a string until there is a space.<br>
  Then split it into a different string after the space.</p>
  
  <p>e.g. String fullcmd = <code>/join luke</code><br>
  I would like to split it into:<br>
  String cmd = <code>/join</code><br>
  String name = <code>luke</code><br>
  OR<br>
  String fullcmd = <code>/leave luke</code><br>
  I would like to split it into:<br>
  String cmd = <code>/leave</code><br>
  String name = <code>luke</code> </p>
  
  <p>So that I can:  </p>
  
  <pre><code>if(cmd.equals"/join") System.out.println(name + " joined.");
  else if(cmd.equals"/leave" System.out.println(name + " left.");
  </code></pre>
  
  <p>I did think about doing <code>String cmd = fullcmd.substring(0,5);</code><br>
  But cmd's length varies depending on the command.</p>