我正在读取一个文件,然后调用一个 string[] 方法,该方法将行分解为单个单词,将每个单词添加到唯一单词数组(无重复单词)中,并返回唯一单词数组。
我不知道如何只打印每个单词一次,但这是我到目前为止所拥有的。
static public String[ ] sortUnique( String [ ] unique, int count)
{
String temp;
for(int i = 1; i < count; i++) {
temp = unique[i].replaceAll("([a-z]+)[,.?]*", "$1");;
int j;
for(j = i - 1; j>= 0 && (temp.compareToIgnoreCase(unique[j]) < 0);j--) {
unique[j+1] = unique[j];
}
unique[j+1] = temp;
}
return unique;
}
这是数据文件。
Is this a dagger which I see before me,
The handle toward my hand? Come, let me clutch thee.
I have thee not, and yet I see thee still.
Art thou not, fatal vision, sensible
To feeling as to sight? Or art thou but
A dagger of the mind, a false creation,
任何帮助将不胜感激!