继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

集合讲解跟学习

一只斗牛犬
关注TA
已关注
手记 531
粉丝 50
获赞 300

package com.dongnao.lsn1


/**

 * Created by xiang on 2017/5/26.

 */



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<String>) {

    //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, B> A.with(that: B): Pair<A, B> = Pair(this, that)

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

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP