Skip to content

Commit 2779300

Browse files
authored
Merge pull request eugenp#4898 from Kirti-Deo/master
BAEL-2024 : java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayList
2 parents 4c4634c + 7afb1b2 commit 2779300

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.baeldung.classcastexception;
2+
3+
import java.util.ArrayList;
4+
import java.util.Arrays;
5+
import java.util.List;
6+
7+
public class ClassCastException {
8+
9+
public static void main(String[] args) {
10+
11+
String p1 = new String("John");
12+
String p2 = new String("Snow");
13+
String[] strArray = new String[] { p1, p2 };
14+
ArrayList<String> strList = (ArrayList<String>) Arrays.asList(strArray);
15+
// To fix the ClassCastException at above line, modify the code as:
16+
// List<String> strList = Arrays.asList(strArray);
17+
System.out.println("String list: " + strList);
18+
19+
}
20+
21+
}

0 commit comments

Comments
 (0)