kodingwindow@kw:~$ javac KW.java kodingwindow@kw:~$ java KW
Length: 13
0th Character: H
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 14
kodingwindow@kw:~$
Java program to handle the StringIndexOutOfBoundsException
KW.java
classKW{publicstaticvoidmain(Stringargs[]){Strings="Hello, World!";System.out.println("Length: "+s.length());System.out.println("0th Character: "+s.charAt(0));try{System.out.println("14th Character: "+s.charAt(14));}catch(StringIndexOutOfBoundsExceptione){System.out.println("Requested character not found");}}}
Output
kodingwindow@kw:~$ javac KW.java kodingwindow@kw:~$ java KW
Length: 13
0th Character: H
Requested character not found
kodingwindow@kw:~$
Dear User, Thank you for visitng Kodingwindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.
Dear User, We are grateful for your interest in the Kodingwindow Android app. We intend to soon make it available on the Google Play Store. Currently, Android versions 10 and up require manual apk installations. Would you like to get the app?