java list转成二维数组(excel中的转置)

public Object[][] selectDetailsV1(Long recordId) {
        List> list = selectMap(recordId);
        int size = list.size();
        /*BudgetMonthly 查询的对象*/
        Field[] declaredFields = BudgetMonthly.class.getDeclaredFields();

        if (CollectionUtils.isEmpty(list)) {
            return new Object[0][];
        }
        Object[][] array = new Object[size + 1][declaredFields.length];
        for (int i = 0; i < size + 1; i++) {
            //循环遍历所有行
            if (i == 0) {
                Map stringObjectMap = list.get(i);
                Set strings = stringObjectMap.keySet();
                array[i] = strings.toArray();
            } else {
                //每行的列数
                array[i] = list.get(i-1).values().toArray();
            }
        }
        return array;
    }

你可能感兴趣的:(java list转成二维数组(excel中的转置))