Converting a list of integers into a two-dimensional array in Java I want to convert a list of integers into a two-dimensional array for use with TestNG DataProvider.  Here is the code I've written:

static List&lt;Integer&gt; studentList = new ArrayList&lt;Integer&gt;();

@Test()
public void testMethod(){
    studentList.add(477915);
    studentList.add(477916);
    studentList.add(477917);
    System.err.println(studentList);
}

@DataProvider(name = "persons")
public static Object[][] primeNumbers() {
    Object [][] objArray = new Object[studentList.size()][];

    for(int i=0;i&lt; studentList.size();i++){
        objArray[i] = new Object[1];
        objArray[i][0] = studentList.get(i);
    } 

    return objArray;
}

@Test(dataProvider="persons")
public void testRunPersonRules(int val) {
    System.err.println(val);
}


Is there a better way to accomplish this?
You can use streams:

Object[][] data = studentList.stream()
        .map(studentId -&gt; new Object[]{studentId})
        .toArray(Object[][]::new);