How to handle nulls when using Java collection sort

后端 未结 6 2113
离开以前
离开以前 2020-12-29 19:39

When using Collection.sort in Java what should I return when one of the inner objects is null

Example:

Collections.sort(list, new Comparator

        
6条回答
  •  悲&欢浪女
    2020-12-29 20:36

    It depends, do you consider null as a big value or a low value.

    You can consider most of the time that null < everything else, but it depends on the context.

    And 0 would be a terrible return value here.

提交回复
热议问题