#155 Unique People by Full Name
Implement unique():
@Data
@AllArgsConstructor
public class Person {
public Integer id;
public String firstName;
public String secondName;
public String patronymicName;
}
@Test
public void test() {
List<Person> persons = new ArrayList<>();
persons.add(new Person(1,"Ivan","Vasya","Petr"));
persons.add(new Person(2,"Ivan","Vasya","Petr"));
persons.add(new Person(3,"Ivan","Vasya","Petr"));
persons.add(new Person(4,"Ivan","Gupta","Ivan"));
persons.add(new Person(5,"Petr","Rama","Igor"));
Collection<Person> uniquePersons = unique(persons);
assert uniquePersons.size() == 3;
}
// Unique collection by the combination of firstName, secondName, and patronymicName
public static Collection<Person> unique(List<Person> persons){
...
}
Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor