且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将 ArrayList 转换为二维数组

更新时间:2023-02-27 07:43:13

我设法找到了一种方法",知道每个联系人具有的属性数量 (6).所以考虑一个 ArrayList listofContacts

I managed to find "a way" to do so, knowing the number of attributes each contacts has (6). So considering an ArrayList listofContacts

    int numberOfContacts = listofContacts.size()/6;
    Object[][] newArrayContent = new Object[numberOfContacts][6];

    for(int x = 0; x<numberOfContacts; x++){
        for(int z = 0; z < 6; z++){
        int y = 6 * x;
        newArrayContent [x][z] = list.get(y+z); 
        System.out.println(newArrayContent [x][z].toString());
        }
    }