title: Issue with Java and StringIndexOutOfBoundsException
body: <p>I am trying to do a school assignment and I am a bit stuck with my code, when I run the code I get this:</p>
  <pre><code>Exception in thread &quot;main&quot; java.lang.StringIndexOutOfBoundsException: begin 0, end -1, length 25
      at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3756)
      at java.base/java.lang.String.substring(String.java:1902)
      at Demo4/d4.StringBuilder.poistaEkaSana(StringBuilder.java:32)
      at Demo4/d4.StringBuilder.main(StringBuilder.java:18)
  </code></pre>
  <p>The goal is to use StringBuilder to remove first name firstname and print characters after space.
  Any help is appreciated.</p>
  <pre><code>import fi.jyu.mit.ohj2.*;
  
  public class StringBuilder {
  
      public static void main(String[] args) {
          String nimi = Syotto.kysy(&quot;Give Lastname Firstname&quot;);
          StringBuilder sb = new StringBuilder();
          removeFirstWord(sb);
  
          System.out.println(&quot;Your last name is &quot; + sb);
          String lastname = giveFirstWord(name);
          System.out.println(&quot;Your last name is &quot; + lastname);
      }
  
  
      public static String removeFirstWord(StringBuilder sb) {
          String bs = sb.toString();
          int remove= bs.indexOf(&quot; &quot;);
          String second= bs.substring(0, remove);
          return second;
  
      }
  
      public static String giveFirstWord(String fname) {
          int s1= fname.indexOf(' ');
          String d2= fname.substring(s1, 14);
          return d2;
      }
  }
  </code></pre>