title: How to split a string from the first space occurrence only Java
body: <p>I tried to split a string using string.Index and string.length but I get an error that string is out of range. How can I fix that?</p>
  
  <pre><code>while (in.hasNextLine())  {
  
      String temp = in.nextLine().replaceAll("[&lt;&gt;]", "");
      temp.trim();
  
      String nickname = temp.substring(temp.indexOf(' '));
      String content = temp.substring(' ' + temp.length()-1);
  
      System.out.println(content);
  </code></pre>