Professional Documents
Culture Documents
12.array List Exception
12.array List Exception
12
Here we are describing the use of using exception class in java .This tutorial describes how to handle Array list exceptions appropriately in your programs and designs. The steps involved in the program are described below:ArraylistException.java import java.util.*; public class ArraylistException { void buildAlphabet() { ArrayList list = new ArrayList(); for (int i =1; i <=5; i++) { list.add(i,(String)("Girish")); } System.out.print("Elements of array are: " + list); } public static void main(String[] args) { ArraylistException ale=new ArraylistException(); ale.buildAlphabet(); } }
To avoid this error you have to give proper index for the List means to say starting index which is 0 for the array not 1.