The program seems to function as expected. But it is failin to pass first requirement.
package com.codegym.task.task10.task1015;
import java.util.ArrayList;
/*
Requirements:
1. The createList method must declare and initialize an array with ArrayList<String> elements.
2. The createList method must return the created array.
3. The createList method must add elements (string lists) to the array. The lists must not be empty.
4. The program should display data on the screen.
5. The main method must call the createList method.
6. The main method must call the printList method.
*/
public class Solution {
public static void main(String[] args) {
ArrayList<String>[] arrayOfStringList = createList();
printList(arrayOfStringList);
}
public static ArrayList<String>[] createList() {
int size = 5;
ArrayList<String>[] listA = (ArrayList<String>[]) new ArrayList[size];
for (int i = 0; i < listA.length; i++) {
listA[i] = new ArrayList<>();
for (int j = 0; j < size; j++) {
listA[i].add("ListA Index = " + i + " ListB Index = " + j);
}
}
return listA;
}
public static void printList(ArrayList<String>[] arrayOfStringList) {
for (ArrayList<String> list : arrayOfStringList) {
for (String s : list) {
System.out.println(s);
}
}
}
}