I\'m new to Java and am trying to understand why the first code snippet doesn\'t cause this exception but the second one does. Since a string array is passed into Arrays.as
If you do this, you won't get any CCE:
ArrayList> stuff = new ArrayList>();
String[] titles = {"ticker", "grade", "score"};
stuff.add(new ArrayList(Arrays.asList(titles)));
As the error clearly states, the class java.util.ArrayList isn't the same as nested static class java.util.Arrays.ArrayList. Hence the exception. We overcome this by wrapping the returned list using a java.util.ArrayList.