JAVA: Preventing Duplicate Entries to an ArrayList

前端 未结 6 1655

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 00:46

    Firstly, use equals to compare strings.

    Secondly, you can use Set rather than a List

    And lastly, you can use contains method to check if the item already exists.

提交回复
热议问题