Infolinks In Text Ads

Jul 1, 2010

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.

Example:-
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)
 */

1 comment:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training in India . Nowadays Java has tons of job opportunities on various vertical industry.


    or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.

    ReplyDelete

LinkWithin

Related Posts Plugin for WordPress, Blogger...