Which of the following should be followed while setting Set elements and why?
private Set<TestDetailEntity> testDetails = new HashSet<>();
public void setTestDetails(Set<TestDetailEntity> testDetails) {
this.testDetails.clear();
this.testDetails.addAll(testDetails);
}
public void setTestDetails(Set<TestDetailEntity> testDetails) {
this.testDetails = testDetails;
}
The first one iterates over the collection. What I am trying to ask here is which one is efficient way?