简体   繁体   English

当无法使用ArrayList时,如何解决列表大小调整问题?

[英]How can I work around a list resizing issue when an ArrayList is not an option to use?

We have a search tool that displays results in a table. 我们有一个搜索工具,可以在表格中显示结果。 The list I have to compose and return has to be something like this: 我必须撰写并返回的列表必须是这样的:

List[] res = new List[(some_int_initializer];
return res;

The problem this poses is that this type of list is not re-sizeable. 造成的问题是这种类型的列表不可调整大小。 This problem poses a problem I have, in which I have to resize this list when I don't 这个问题给我带来了一个问题,当我不这样做时,我必须重新调整列表的大小

    while(collection.iterator().hasNext())
    {
        StringBuilder sb = new StringBuilder();
        sb.append("C:\\test\\sage\\data\\");
        List<String> myList = collection.iterator().next();

        // iterate through string list and compose file paths
        for(String name: myList)
        {
            Matcher matcher = samplePattern.matcher(sampleName);

            if(matcher.find())
            {
                sb.append(matcher.group(1));
                sb.append(matcher.group(2));
                sb.append(matcher.group(3));
                sb.append("000\\nmr\\");
                sb.append(name);
            }

            File file = new File(sb.toString());
            int counter = 0;
            List[] res = new List[myList.size()];

            if(file.exists())
            {
                File[] dirs = file.listFiles();

                for(int step=0;step<dirs.length;step++)
                {
                    List row = new ArrayList();
                    row.add(name);
                    row.add(dirs[step].getAbsolutePath());
                    res[counter++] = row;
                }
            }
        }
    }

The name and path have to be displayed on a row, but a name can have more than one path associated with it. 名称和路径必须显示在一行上,但是名称可以具有多个关联的路径。 Also, even if the file path does not exist, the name still show in the table. 此外,即使文件路径不存在,该名称仍会显示在表中。 This is make it really difficult to resize the list, especially when I have to add each Array list to 'res'. 这确实很难调整列表的大小,尤其是当我必须将每个Array列表添加到“ res”时。

Any thoughts or ideas appreciated. 任何想法或想法表示赞赏。

UPDATE 更新

Thanks to all who have responded. 感谢所有回应。 This is the solution that worked for me: 这是为我工作的解决方案:

 List[] results = allRows.toArray(new List[allRows.size()]);

Thanks to all who have responded. 感谢所有回应。 This is the solution that worked for me: 这是为我工作的解决方案:

List[] results = allRows.toArray(new List[allRows.size()]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM