Java 当方法为';s的大小是动态的?

Java 当方法为';s的大小是动态的?,java,apache-poi,Java,Apache Poi,您好,我有下面的一段代码,这里我必须从这个函数返回存储在数组s[][]中的数据,请帮助我如何做 public static String[][] readxl(String filepath) throws FileNotFoundException, IOException { FileInputStream file = new FileInputStream(new File(filepath)); HSSFWorkbook

您好,我有下面的一段代码,这里我必须从这个函数返回存储在数组
s[][]
中的数据,请帮助我如何做

 public static String[][] readxl(String filepath) throws FileNotFoundException, IOException
        {
            FileInputStream file = new FileInputStream(new File(filepath));
            HSSFWorkbook workbook = new HSSFWorkbook(file);
            HSSFSheet sheet = workbook.getSheetAt(0);
            int rowcount = sheet.getPhysicalNumberOfRows();
            Row row1 = sheet.getRow(0);
            int colcount=row1.getPhysicalNumberOfCells();
            String[][]s = new String[rowcount][colcount];
            for(int i=0;i<sheet.getPhysicalNumberOfRows();i++)
            {
                Row row = sheet.getRow(i);
                for(int j=0; j<row.getPhysicalNumberOfCells();j++)
                {
                    Cell c = sheet.getRow(i).getCell(j);
                    int celltype = c.getCellType();
                    if(celltype==1)
                    {
                        s[i][j] =c.getStringCellValue();               
                    }
                    if(celltype==0)
                    {   
                        s[i][j] =String.valueOf((int)c.getNumericCellValue()); 
                    }

                }
            }
publicstaticstring[]readxl(stringfilepath)抛出FileNotFoundException、IOException
{
FileInputStream file=newfileinputstream(新文件(filepath));
HSSF工作簿=新的HSSF工作簿(文件);
HSSFSheet sheet=工作簿。getSheetAt(0);
int rowcount=sheet.getPhysicalNumberOfRows();
行row1=sheet.getRow(0);
int colcount=row1.getPhysicalNumberOfCells();
字符串[][]s=新字符串[rowcount][colcount];
对于(int i=0;i您可以直接使用

return s;
即使大小是动态的,返回数组也没有问题

祝你好运。

你可以直接使用

return s;
即使大小是动态的,返回数组也没有问题


祝你好运。

如果其动态不使用数组,请使用
集合
ArrayList
ArrayList
(2D)例如);数组=固定大小如果其动态不使用数组,请使用
Collection
ArrayList
(2D)的
ArrayList
);数组=固定大小