Problem in using java arraylist getting ArrayStoreException?

Listlist[]=new ArrayList[2];
list[0]=Arrays.asList(new Integer[]{1,2,3});
System.out.println(list[0]);

CONSOLE LOG

Exception in thread "main" java.lang.ArrayStoreException: java.util.Arrays$ArrayList
at problems.codechef.Experiment.main(Experiment.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

Can anyone tell me what is the bug in this code.

change List<Integer>list[]=new ArrayList[2]; to List<Integer>list[]=new List[2];

1 Like

@ankushsood

ArrayListlist[]=new ArrayList[2];

list[0]=(ArrayList)Arrays.asList(1,2);

And why this code is giving an exception.