/* package whatever; // don't place package name! */

import java.util.*;
import java.util.stream.Collectors;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
    public static void main ( String[] args ) throws java.lang.Exception
    {
        List < CountryCount > listOfCountryCount = List.of(
                new CountryCount( "Peru" , 17L ) ,
                new CountryCount( "Xanadu" , 128L ) ,
                new CountryCount( null , 42L ) ,
                new CountryCount( "Andorra" , null )
        );

		NavigableMap < String, Long > map =
		        listOfCountryCount
		                .stream()
		                .collect(
		                        Collectors.toMap(
		                                countryCount -> Objects.isNull( countryCount.getCountry() ) ? "unknown" : countryCount.getCountry() ,
		                                countryCount -> Objects.isNull( countryCount.getCount() ) ? Long.valueOf( 0 ) : countryCount.getCount() , 
		                                ( existing , replacement ) -> existing ,  // In case of duplicate key conflict, first one wins.
		                        		TreeMap :: new 
		                        )
		                );
		                
        System.out.println( "listOfCountryCount = " + listOfCountryCount );
        System.out.println( "map = " + map );
    }
}

final class CountryCount
{
    private final String country;
    private final Long count;

    CountryCount ( String country , Long count )
    {
        this.country = country;
        this.count = count;
    }

    public String getCountry ( ) { return country; }

    public Long getCount ( ) { return count; }

    @Override
    public boolean equals ( Object obj )
    {
        if ( obj == this ) return true;
        if ( obj == null || obj.getClass() != this.getClass() ) return false;
        var that = ( CountryCount ) obj;
        return Objects.equals( this.country , that.country ) &&
                Objects.equals( this.count , that.count );
    }

    @Override
    public int hashCode ( )
    {
        return Objects.hash( country , count );
    }

    @Override
    public String toString ( )
    {
        return "CountryCount[" +
                "country=" + country + ", " +
                "count=" + count + ']';
    }
}