ITPub博客

首页 > IT职业 > IT职场 > 集合讲解跟学习

集合讲解跟学习

IT职场 作者:yaweche 时间:2021-09-09 09:48:42 0 删除 编辑

package com.dongnao.lsn1




fun test(i: Int = 100, j: String = "") {


}


fun test(j: String = "") {

    val i = 100

}

//可变参数

fun test(vararg item: Int) {

    item.forEach { }

}



inline fun String.show() {


}


inline val String.lastChar: Char

    get() = get(length - 1)



fun main(args: Array) {

    //list集合

    val list = listOf(1, 2, 3, 4)

    list[0]

    list.last()

    //遍历集合

    for (i in list) {


    }

    list.forEach {

        item ->

        println(item)

    }


    list.forEachIndexed { index, i -> }


    list.joinToString()


    //默认参数函数调用

    test()

    test(1)

    test(1, "11")

    test(j = "22")


    //可变长度参数

    test(1, 2, 3, 4, 5, 6, 7)


    //扩展方法

    "".show()



    //map映射集合

    val map = mapOf(1 to "a", 2 to "b", "c" to 1)


    //获取对应key元素

    map[1]

    map["c"]


    //中缀调用 infix

    1 to "a"

    1.to("a")


    //中缀方法

    1 with "a"


    //析构声明

    val pair = "a" to "b"

    val (key, value) = pair



    val compile = "com.android.support.constraint:constraint-layout:1.0.2"


    val (group, name, version) = compile.split(":")



}



infix fun A.with(that: B): Pair = Pair(this, that)

原文链接:http://www.apkbus.com/blog-340477-76708.html

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4257/viewspace-2812878/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-12

  • 博文量
    0
  • 访问量
    970