Hi!
Please help, I am not sure why it does not pass the tests. I strongly suspect that it is about line 20:
ArrayList<String>[] result = (ArrayList<String>[])new ArrayList[size];
I tried several ways to declare this array but no luck. As per Oracle's documentation, we Cannot Create Arrays of Parameterized Types.
Please give me a hint here.
Thanks!package com.codegym.task.task10.task1015;
import java.util.ArrayList;
import java.util.List;
/*
Array of string lists
*/
public class Solution {
public static void main(String[] args) {
ArrayList<String>[] arrayOfStringList = createList();
printList(arrayOfStringList);
}
public static ArrayList<String>[] createList() {
int size = 3;
ArrayList<String>[] result = (ArrayList<String>[])new ArrayList[size];
// ArrayList<String>[] result = new ArrayList[size];
for (int i = 0; i < size; i++) {
ArrayList<String> list = new ArrayList<>();
for (int j = 0; j < size; j++) {
list.add(i + " " + j + " " + Double.toString(Math.random()));
}
result[i] = list;
}
return result;
}
public static void printList(ArrayList<String>[] arrayOfStringList) {
for (ArrayList<String> list : arrayOfStringList) {
for (String s : list) {
System.out.println(s);
}
}
}
}