comparator with null values

前端 未结 9 1169
萌比男神i
萌比男神i 2020-12-04 16:25

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

9条回答
  •  感动是毒
    2020-12-04 16:52

    You probably dont want to return 0 as that implies the addresses are equidistant and you really dont know. This is quite a classic problem where you are trying to deal with bad input data. I dont think its the responsibility of the comparator to try and determin how far the address is in realtive terms when you dont know the distance. I would remove those addresses from the list before sorting.

    The hack would be to move them to the bottom of the list (but thats ugly !)

提交回复
热议问题