我试图使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++)