Am I adding the arrays correctly?
package com.codegym.task.task09.task0926;
import java.util.ArrayList;
/*
List of number arrays
Create a list whose elements are arrays of numbers.
Add to the list five array objects whose lengths are 5, 2, 4, 7, and 0, respectively.
Fill the arrays with any data and display them on the screen.
Requirements:
1. The program must not read data from the keyboard.
2. The createList method must declare and initialize an ArrayList<int[]> variable.
3. The createList method must return the created list.
4. The createList method must add 5 elements to the list.
5. Each element in the list must be an array of numbers. The length of the first array must be 5; the second — 2; and the rest — 4, 7, and 0, respectively.
6. The program should display the elements of all the arrays in the list. Each element on a new line.
*/
public class Solution {
public static void main(String[] args) {
ArrayList<int[]> list = createList();
printList(list);
}
public static ArrayList<int[]> createList() {
ArrayList<int[]> list = new ArrayList<>();
int[] five = {1, 2, 3, 4, 5};
int[] two = {1, 2};
int[] four = {2, 3, 5, 6};
int[] seven = {1, 32, 4, 5, 6, 7, 8};
int[] zero = {};
list.add(0, five);
list.add(2, two);
list.add(3, four);
list.add(4, seven);
list.add(5, zero);
return list;
}
public static void printList(ArrayList<int[]> list) {
for (int[] array : list) {
for (int x : array) {
System.out.println(x);
}
}
}
}