我有一个void方法,它应该接受一个字符串并根据分隔符将它分成两个字符串。使用调试器后,该方法似乎正常工作,但传递给存储结果的方法的两个空字符串似乎没有更新。我必须在这里做一些愚蠢的事情,但任何帮助表示赞赏!void方法不会操纵字符串
public static void main(String[] args) {
String dictFile = "/Users/simonrhillary/Desktop/Dictionary(3).txt";
String synFile = "/Users/simonrhillary/Desktop/Synonyms(2).txt";
fileReader dictFR = new fileReader();
fileReader synFR = new fileReader();
dictFR.filePath = dictFile;
synFR.filePath = synFile;
dictFR.openFile(dictFile);
synFR.openFile(synFile);
String[] dictionary = dictFR.fileToArray();
String[] synonyms = synFR.fileToArray();
String regx = "^[aflmptu]+$";
String regexTemplate = "^[]+$";
String word1 = "";
String word2 = "";
synToWords(synFR.getLine(3), word1, word2);//error seems to be here.
//word1 and word 2 stay ""
System.out.println(word1 +" " + word2);
printArray(findCombos(dictionary, word1, word2));
}
public static void synToWords(String syn, String wordI, String wordII){
String[] words = syn.split("\\t");
wordI = wordI + words[0];
wordII = wordII + words[1];
}
还有其他的方法我没有发布,但他们都工作正常。这只是synToWords方法的问题所在。非常感谢!
好的我认为这可能是这样的,我应该改变返回类型并运行该方法两次吗? –
最好不要将方法拆分出来,或者更好的是使用'Scanner'。 –