Merge pull request #4898 from Kirti-Deo/master

BAEL-2024 : java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayList
This commit is contained in:
daoire 2018-08-24 07:59:47 +01:00 committed by GitHub
commit 2779300352
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,21 @@
package com.baeldung.classcastexception;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ClassCastException {
public static void main(String[] args) {
String p1 = new String("John");
String p2 = new String("Snow");
String[] strArray = new String[] { p1, p2 };
ArrayList<String> strList = (ArrayList<String>) Arrays.asList(strArray);
// To fix the ClassCastException at above line, modify the code as:
// List<String> strList = Arrays.asList(strArray);
System.out.println("String list: " + strList);
}
}