谁能给我这个方法和任何问题的简要解释。我认为它是输入少于 5 个单词的行并在制表符、换行符等上拆分行,然后进行比较以查找输入行中单词的重复。
public static void findNeedles(String haystack, String[] needles){
if(needles.length > 5){
System.err.println("Too many words!");
}
else{
int[] countArray = new int[needles.length];
for(int i = 0; i < needles.length; i++){
String[] words = haystack.split("[ \"\'\t\n\b\f\r]", 0);
for(int j = 0; j < words.length; j++){
if(words[j].compareTo(needles[i]) == 0){
countArray[i]++;
}
}
}
for (int j = 0; j < needles.length; j++) {
System.out.println(needls[j] + ": " + countArray[j]);
}
}
}