Tuesday, October 2, 2012

ArrayIndexOutOfBoundsException Example in Java

import java.util.*;
public class ArrayIndexOutOfBoundsException {

    public static void main(String[] args) {
           
            String []array = new String[0];
            array[0] = "0";
            System.out.println("String []array ? " + array[0]);

    }

}

Answer
--------
The following error occurs

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at ArrayIndexOutOfBoundsException.main(ArrayIndexOutOfBoundsException.java:7)

No comments:

Post a Comment