标签:class ring nbsp 属性 调用 span col main style
1.
var list1 = listOf(1, 3, 5) // println(list1.map { it * 10 })//[10, 30, 50] //筛选list println(list1.filter { it>3 }) //[5] //筛选list 后的个数 print(list1.count{it>3}) //1 //求和 print(list1.sum())//9
2.对象里的某个属性求和
data class Student(val name:String,val score:Int) fun main() { val student1 = Student("tom", 100) val student2 = Student("liu", 100) val student3 = Student("li", 150) var list= listOf(student1,student2,student3) print(list.sumBy { it.score }) //350 }
3.递归
var list1 = listOf(1, 3, 5) //递归调用fold(n)里的n是初始值 print(list1.fold(2) { n, s -> n * s })
标签:class ring nbsp 属性 调用 span col main style
原文地址:https://www.cnblogs.com/buchizaodian/p/12642129.html