JAVA: Preventing Duplicate Entries to an ArrayList

前端 未结 6 1654

I am trying to prevent duplicate entries from being added to an ArrayList as the list is being populated whilst reading through each line of a file. Each line of the file is

6条回答
  •  迷失自我
    2021-01-12 01:05

    For each addition to the ArrayList you will have to iterate over all previous entries and check if duplicates entry exists(You can use .contains()) which is O(N).

    Better I would suggest use a set.

提交回复
热议问题