Simple explanation about what a Index out of bound exception is:
Just think one train is there its compartments are D1,D2,D3. One passenger came to enter the train and he have the ticket for D4. now what will happen. the passenger want to enter a compartment that does not exist so obviously problem will arise.
Same scenario: whenever we try to access an array list, etc. we can only access the existing indexes in the array. array[0]
and array[1]
are existing. If we try to access array[3]
, it's not there actually, so an index out of bound exception will arise.