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
System.out.println(name);
}
}
//output
C:\JAVA>java Test
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String ind
ex out of range: 6
at java.lang.String.<init>(String.java:211)
at Test.main(Test.java:13)