java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayList

Arrays.asList returns a List implementation, but it’s not a java.util.ArrayList. It happens to have a classname of ArrayList, but that’s a nested class within Arrays – a completely different type from java.util.ArrayList.

If you need a java.util.ArrayList, you can just create a copy:

ArrayList<Foo> list = new ArrayList<>(Arrays.asList(sos1.getValue()); 

If you don’t need an ArrayList just remove the cast:

List<Foo> list = Arrays.asList(sos1.getValue()); 

(if you don’t need any members exposed just by ArrayList).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)