We have some code which sorts a list of addresses based on the distance between their coordinates. this is done through collections.sort with a custom comparator.
How
No, there is no cleaner way. Perhaps:
But more importantly - try to get rid of / fill in the missing coordinates, or, better: don't put addresses with missing coordinates in the list.
Actually, not putting them in the list is the most logical behaviour. If you put them in the list, the result won't be actually ordered by distance.
You may create another list, containing the addresses with missing coordinates, and make it clear to whoever needs that information (end-user, API user), that the first list only contains addresses with the needed data, while the second list contains addresses that lack required information.