When using the Java substring() method, a subset of the character sequence can be extracted from a string. The substring
index must be any value from 0 to the length of a string. The java.lang.StringIndexOutOfBoundsException thrown by String methods to indicate that the beginIndex is negative , or endIndex is larger than the length of this String object, or beginIndex is larger than endIndex.
How to solve the StringIndexOutOfBoundsException
Check the length of the string before using substring()
Exception handling using try...catch.