Posts

Showing posts from October, 2017

IndexOutOfBoundsException

IndexOutOfBoundsException java.lang.Object java.lang.Throwable java.lang.Exception java.lang.RuntimeException java.lang.IndexOutOfBoundsException public class IndexOutOfBoundsException extends RuntimeException It comes with two subclasses used very often in coding with arrays and strings. 1.       ArrayIndexOutOfBoundsException 2.       StringIndexOutOfBoundsException IndexOutOfBoundsException : check the index number entered by the user is within the range of an array or string. List<String> list1 = new ArrayList<String>(5); for(int i=0;i<10;i++){       list1.add(6,String.valueOf(i)); } ArrayIndexOutOfBoundsException : When Trying to get or put value from index which is the bigger than size of array String[] myArray = new String[3]; myArray[4] = "ratik"; System.out.println("myArray..." + myArray[4].toString()); StringIndexOutOfBoundsException :   Wh