This is my code, after initialized the array, I cannot able to reassign some value in array. It shows array index out of bound exception.
public class NewClass {
public static void main(String args[]){
String cl[]={};
cl[0]="10";
System.out.print(cl.length);
}
}
my output:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at NewClass.main(NewClass.java:15)
Java Result: 1
clarray size is0and you trying to insert value sojava.lang.ArrayIndexOutOfBoundsExceptionyou can go for dynamic list such asList<String> c1=new ArrayList<>();