美文网首页
2019-05-23 Kotlin中的列表排序

2019-05-23 Kotlin中的列表排序

作者: 兣甅 | 来源:发表于2019-05-23 11:04 被阅读0次

    1.正序

    val list: MutableList<CommentBean> = mutableListOf()
    list.sortByDescending { it.time }
    

    2.倒序

    val list: MutableList<CommentBean> = mutableListOf()
    list.sortByDescending { it.time }
    
    data class CommentBean(
      var id: Long = 0,
      var userBean: UserBean,
      var content: String = "",
      var praiseNum: Int = 0,
      var score: Double = 0.0,
      var time: Long = 0L,
      var isPraise: Boolean = false,
      var commentList: MutableList<CommentBean> = mutableListOf(),
      var commentSize: Int = 0
    )
    
    data class UserBean(
      var uid: Long,
      var head: String? = null,
      var gender: String? = null,
      var age: String? = null,
      var birth: String? = null,
      var city: String? = null,
      var id: String? = null,
      var desc: String? = null,
      var headBg: String? = null,
      var name: String? = null
    ) 
    

    相关文章

      网友评论

          本文标题:2019-05-23 Kotlin中的列表排序

          本文链接:https://www.haomeiwen.com/subject/yghvzqtx.html