Skip to content

Commit 7afb1b2

Browse files
committed
BAEL-2024 : Fixed review comments by Darragh.
1 parent 8136464 commit 7afb1b2

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

‎core-java/src/main/java/com/baeldung/classcastexception/ClassCastException.java‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ public class ClassCastException {
88

99
public static void main(String[] args) {
1010

11-
List<ArrayList<String>> strList = new ArrayList<ArrayList<String>>();
12-
// To correct the Exception at line #18, modify the line #11 code as:
13-
// List<List<Person>> personList = new ArrayList <List<Person>>();
14-
// Line #18 code as personList.add(Arrays.asList(personArray));
1511
String p1 = new String("John");
1612
String p2 = new String("Snow");
1713
String[] strArray = new String[] { p1, p2 };
18-
strList.add((ArrayList<String>) Arrays.asList(strArray));
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);
1917
System.out.println("String list: " + strList);
2018

2119
}

0 commit comments

Comments
 (0)