[Solved] Java List not contains object [closed]
Your attempt won’t work since you’re handling the creation in the loop, so you will end up adding several persons there. Just write it the way you described it: if (allPersons.isEmpty() || !allPersons.contains(person)) allPersons.add(person) Now, in order for this to work you have to ask yourself an important question: What exactly constitutes “the same person”? … Read more