Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javamultiplex/56ccb3046f75d5228ca193dd2644b8a1 to your computer and use it in GitHub Desktop.
Save javamultiplex/56ccb3046f75d5228ca193dd2644b8a1 to your computer and use it in GitHub Desktop.
Example of ArrayIndexOutOfBoundsException present in java.lang package
package com.javamultiplex.java.lang.exceptions;
/**
* @author Rohit Agarwal
* @version 1.0
* @category java.lang/Exception
* @since JDK 1.0
*/
public class ArrayIndexOutOfBoundsExceptionDemo {
public static void main(String[] args) {
int arr[] = new int[5];
/*
* ArrayIndexOutOfBoundException will be thrown because array size is 5
* whose min index is 0 and max index is 4. We are trying to access
* element at index 5 that not exists.
*/
System.out.println(arr[5]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment