Java - String index out of bound exception example

// Example of String index  out of bound exception

class Test

public static void main(String a[])

char ar[]={'a','e','i','o','u'};   //Character array having five elements

String name=new String(ar,1,5);          //Exception fires here





C:\JAVA>java Test
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String ind
ex out of range: 6
       at java.lang.String.<init>(
       at Test.main(