我有几百行代码的字符串数组。我还有另外两个字符串数组,一个带有我想替换的值,另一个带有我想替换的值。我需要遍历原始代码的每一行,检查每一行是否包含需要替换的内容,如果包含,则替换。我想将它替换为一个完全不同的字符串数组,这样原始的字符串仍然保持不变。这就是我所拥有的,但并不完全有效。
for(int i=0; i<originalCode.length; i++) {
if( originalCode[i].contains("| "+listOfThingsToReplace[i]) ) {
newCode[i]=originalCode[i].replaceAll(("| "+listOfThingsToReplace[i]), ("| "+listOfReplacingThings[i]));
}
}
显然我需要更多的计算变量(特别是因为 originalCode.length !=listOfThingsToReplace.length
),但我不知道在哪里。我需要更多吗?我厌倦了那样做。。。“但是” Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
"... 需要帮忙吗?
1条答案
按热度按时间2ul0zpep1#
我想如果我正确理解这个问题的话,这个方法就可以了