これが私のコードです:
public static void deleteDuplicates(ArrayList<String> list){
ArrayList<String> newList = new ArrayList<String>();
HashSet<String> set = new HashSet<String>();
for(int i = 0; i < list.size(); i++){
set.add(list.get(i));
}
newList.addAll(set);
return newList;
}
これに対する私の入力は次のとおりです。
1, 2, 2, 3, 4, 3, 1, 5, 5, 4, 1, 4, 5
そして、私が得ている出力は次のとおりです。
3, 2, 4, 1, 5
なぜこれが故障しているのか誰かが説明できますか?