I need to create Map<String, String> from List<Person> using Stream API.
persons.stream()
.collect(Collectors
.toMap(Person::getNationality, Person::getName, (name1, name2) -> name1)
But in the above case, I want to resolve conflict in name attribute by using Person's age. is there any way to pass merge function something around the lines (age1, age2) -> // if age1 is greater than age2 return name1, else return name2 ?