Setter method for an object using a special logic I have a method that received a list of CoordinateBE : setExits(..)
I want to update the existing coordinates list with a new coordinate only if there is no coordinate in the current list that has the same latitude and longitude.
Example:
List: [Coordinate: lat:23, long:24, Coordinate: lat:34, long:24]
I am trying to add a new Coordinate: Coordinate: lat:23, long: 24 ---&gt; this one I cannot add it because already exists in the list.
My implementation is working, but I was wondering if I can improve it, for example through lambda expressions, etc. Do you have any ideas?
// setter
  public void setExits(final List&lt;CoordinateBE&gt; exits) {
            if (getExits().isEmpty()) {
                this.exits = exits;
            } else {
                if (!existenceOfCoordinates(getExits(), exits)) {
                    final List&lt;CoordinateBE&gt; result = new ArrayList&lt;&gt;();
                    result.addAll(getExits());
                    result.addAll(exits);
                    this.exits = result;
                }
            }
        }

//getter
  public List&lt;CoordinateBE&gt; getExits() {
     return exits;
  }

// existenceOfCoordinates
 private boolean existenceOfCoordinates(final List&lt;CoordinateBE&gt; existingCoordinates, final List&lt;CoordinateBE&gt; currentCoordinates) {
    for (final CoordinateBE existingCoordinate : existingCoordinates) {
        for (final CoordinateBE currCoordinateBE : currentCoordinates) {
            if (compareCoordinates(existingCoordinate, currCoordinateBE)) {
                return false;
            }
        }
    }
    return true;
 }

// compareCoordinates
 private boolean compareCoordinates(final CoordinateBE existingCoordinate, final CoordinateBE newCoordinate) {
        return existingCoordinate.getLatitude().equals(newCoordinate.getLatitude())
                &amp;&amp; existingCoordinate.getLongitude().equals(newCoordinate.getLongitude());
    }
Why do you recreate this.exits every time you add new items? This:
                    final List&lt;CoordinateBE&gt; result = new ArrayList&lt;&gt;();
                    result.addAll(getExits());
                    result.addAll(exits);
                    this.exits = result;

could be simplified to
                    this.exits.addAll(exits);


If coordinates are always meaningfully equal based on latitude + longitude, you may want to override equals() and hashCode() so that so you can better leverage built-in methods. With an overrided equals(), you would not need compareCoordinates, and existenceOfCoordinates could be replaced with collection methods.
For example:
private boolean existenceOfCoordinates2(List&lt;CoordinateBE&gt; a, List&lt;CoordinateBE&gt; b) {
  return b.stream().anyMatch(a::contains);
}


With the above simplifications, (I'll skip the equals() override in case you actually don't want that), it's distilled down to:
public void setExits(final List&lt;CoordinateBE&gt; exits) {
  if (!getExits().isEmpty()) {
    // Check that no new exits are already in the list
    for (CoordinateBE exit : getExits()) {
      if (exits.stream().anyMatch(x -&gt; compareCoordinates(x, c))) {
        return;
      }
    }
  }

  this.exits.addAll(exits);
}


// If CoordinateBE overrides equals(), you could also do:

public void setExits(final List&lt;CoordinateBE&gt; exits) {
  // In this case, I'm not checking whether this.exits is empty, because
  // we're streaming the new exits as opposed to the current, and that stream
  // will just be empty if the new exits are empty.
  if (exits.stream().anyMatch(this.exits::contains)) {
    return;
  }
  this.exits.addAll(exits);
}


Finally, I am assuming that order is important here, which is why you're using a List as opposed to a Set. Even so, if you're okay with overriding equals() and if duplicates are not allowed, using a LinkedHashSet for this.exits would likely be faster beyond lists of a few dozen elements.