The .substring() method pulls out a portion of a string. It takes a start index (inclusive) and an optional end index (exclusive).
String s = "HelloWorld";
String sub1 = s.substring(5);
String sub2 = s.substring(0, 5);
System.out.println(sub1);
System.out.println(sub2);
This prints World and then Hello. The one-argument form takes everything from the start index to the end of the string. The two-argument form takes characters from the start index up to, but not including, the end index.
The exclusive end index trips up many beginners. If you want characters at positions through , you pass substring(0, 5), not substring(0, 4). Think of the end index as "stop before this position." If either index is out of range, Java throws a StringIndexOutOfBoundsException.