---
# System prepended metadata

title: Untitled

---

Set interface contains no duplicated elements, In the example below the soccer player "Lionel Messi" appears twice, fix the SoccerPlayer class in order that Set interface works properly






import java.util.HashSet;
import java.util.Set;

public class CollectionTest {

    public static void main(String[] args) {
        Set<SoccerPlayer> soccerPlayers = new HashSet<>();
        soccerPlayers.add(new SoccerPlayer("Lionel", "Messi"));
        soccerPlayers.add(new SoccerPlayer("Cristiano", "Ronaldo"));
        soccerPlayers.add(new SoccerPlayer("Lionel", "Messi"));

        print(soccerPlayers);
    }

    private static void print(Set<SoccerPlayer> soccerPlayers) {
        soccerPlayers.forEach(soccerPlayer -> System.out.println(soccerPlayer));
    }
}

class SoccerPlayer {
    private final String name;
    private final String lastName;

    public SoccerPlayer(String name, String lastName) {
        this.name = name;
        this.lastName = lastName;
    }

    @Override
    public String toString() {
        return "Soccer Player = {" +
                "name=" + name + "," +
                "lastName=" + lastName+
                "}";
    }
}