arrayindexoutofboundsexception in java

Solutions on MaxInterview for arrayindexoutofboundsexception in java by the best coders in the world

showing results for - "arrayindexoutofboundsexception in java"
Romeo
10 Jul 2018
1public class ArrayIndexOutOfBoundException {  
2  
3    public static void main(String[] args) {  
4		String[] arr = {"Mario","Giuseppe","Francesco","Alessandro"};   
5		//Declaring 4 elements in the String array                                       
6          
7        for(int i=0;i<=arr.length;i++) {       
8  
9		//Here, no element is present at the iteration number arr.length, i.e 4  
10            System.out.println(arr[i]);      
11		//So it will throw ArrayIndexOutOfBoundException at iteration 4           
12        }  
13  
14    }  
15  
16}