How to sort a list by existing properties

前端 未结 3 1541
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-15 00:46

I am using this line here to sort a list based on the object\'s name.

g.V.sort{it.name}

How do I sort it based on \"name\" if it exists, if not

3条回答
  •  醉酒成梦
    2021-02-15 01:01

    You can sorts the Collection using a Comparator.

    g.V.sort { a, b ->
        a.name <=> b.name ?: a.title <=> b.title
    }
    

提交回复
热议问题