what is StringIndexOutOfBoundsException in java code example

StringIndexOutOfBoundsException :-

StringIndexOutOfBoundsException is thrown by the String class,
if index in the string is passing greater then the string size
or negative value of index in string.

public class Test {
        public static void main(String[] args) {       
String str = "hello my friends";
            String str1 = str.substring(20);

 * Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -4
    at java.lang.String.substring(String.java:1938)
    at java.lang.String.substring(String.java:1905)
    at com.Test.main(Test.java:11)

Popular posts from this blog

What is NBioBSP Java Library?

Draw arrow line example

Capture image from webcam java code, examples