java - 错误 : cannot find symbol- variable. 引用 ".length"

标签 java arrays for-loop replace

我试图将 storyList 数组中的每个“ADJEKTIVER”字符串变成我的 adjectivesList 数组中的随机字符串。当我尝试编译时,我只收到错误:找不到符号变量。以 .length 作为变量/属性。一直在寻找解决方案

    ArrayList<String> storyList = new ArrayList<String>();
    storyList = reader.getWordsInFile(storyFilename);

    ArrayList<String> adjectivesList = new ArrayList<String>();
    adjectivesList = reader.getWordsInFile(adjectivesFilename);

    for (int index =0; index < storyList.length; index++)
    {
        storyList[index] = storyList[index].replace("ADJEKTIV", adjectivesList[random.nextInt(adjectivesList)]);
    }

    writer.write(adjectivesList, outputFilename);

最佳答案

使用storyList.size()方法而不是storyList.length

for (int index =0; index < storyList.size(); index++)

关于java - 错误 : cannot find symbol- variable. 引用 ".length",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33084232/

相关文章:

java - Spring Security 身份验证管理器不会被自定义过滤器选中

c - 如何将数组分成 block

java - 将包含 NULL 的字节数组转换为字符串

java - 动态添加 JTextField - Java

arrays - 如何在Golang中生成直方图以制作简单的条形图

java - Java 中整数到 int[] 的转换

java - 没有名为 X 的 EntityManager 的持久性提供程序 - JPA

java - 如何使用分水岭改进图像分割?

java - 在计算器程序中实现模运算符

c++ - 无法删除 SDL Poll Events 中的多个元素