この割り当てでは、ソートされた文字列の ArrayList をパラメーターとして取り、リストから重複を排除するメソッド removeDuplicates を作成します。
たとえば、list という変数に次の値が含まれているとします。
{"be", "be", "is", "not", "or", "question", "that", "the", "to", "to"}
removeDuplicates(list) を呼び出した後、リストには次の値が格納されます。
{"be", "is", "not", "or", "question", "that", "the", "to"}
ほぼダウンしていますが、何らかの理由で、リストに含まれている場合
["duplicate", "duplicate", "duplicate", "duplicate", "duplicate"]
2つを除いてすべて削除され、[複製]ではなく[複製、複製]になります
これが私のコードです:
private static void removeDuplicates(ArrayList<String> thing) {
for (int i = 0; i < thing.size(); i++) { // base word to compare to
String temp = thing.get(i);
for (int j = 0; j < thing.size(); j++) { // goes through list for match
String temp2 = thing.get(j);
if (temp.equalsIgnoreCase(temp2) && i != j) { // to prevent removal of own letter.
thing.remove(j);
}
}
}
}