Saturday, 12 April 2014

Class StringIndexOutOfBoundsException

  • java.lang.Object
    • java.lang.Throwable
      • java.lang.Exception
        • java.lang.RuntimeException
          • java.lang.IndexOutOfBoundsException
            • java.lang.StringIndexOutOfBoundsException
              • if index in the string is passing greater then the string size 
                or negative value of index in string.

                        class Example {

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

                        }





                    out put:
                    Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String ind
                    ex out of range: -4
                            at java.lang.String.substring(String.java:1937)
                            at java.lang.String.substring(String.java:1904)
                            at Example.main(Example.java:9)

No comments:

Post a Comment