Step into Kotlin - 09 - 集合
来源:互联网 发布:阅微草堂笔记 知乎 编辑:程序博客网 时间:2024/05/09 20:28
目录
- 集合
- List
- 概念
- 定义 List
- MutableList
- 概述
- 使用
- List 相关操作
- List
- 集合
摘要
空 List,创建 List,创建可变 List
集合
List
概念
List
在 Kotlin 中是不可变的,创建后就不允许作任何修改操作。
定义 List
- 可以使用
listOf()
来创建含有元素的 List,数据类型由 Kotlin 根据初始化元素自动进行推断 - 可以使用
emptyList<T>()
创建空 List,但是必须显示指定数据类型
val empty = emptyList<Int>()val list = listOf("a", "b", "c")println(list) // [a, b, c]
MutableList
概述
MutableList 是可变的 List。底层由 LinkedList 实现。
使用
val mList = linkedListOf("a", "b", "c")mList.add("d")println(mList) // [a, b, c, d]
List 相关操作
val names = listOf("Mike", "Peter", "Jane", "Mary")names filter { it.startsWith("M")} sortBy { it}map { it.toUpperCase()}forEach { print("${it},") }println() // MARY,MIKE,
0 0
- Step into Kotlin - 09 - 集合
- Step into Kotlin
- Step into Scala - 09 - 集合
- Step into Kotlin - 01 - 入门
- Step into Kotlin - 02 - 数据类型
- Step into Kotlin - 04 - 函数
- Step into Kotlin - 06 - 异常
- Step into Kotlin - 08 - 数组
- Step into Kotlin - 11 - 类
- Step into Kotlin - 13 - 包
- Step into Kotlin - 14 - 继承
- Step into Kotlin - 15 - 注解
- Step into Kotlin - 17 - 泛型
- Step into Kotlin - 22 - Xml
- Step into Kotlin - 24 - delegate
- Step into Kotlin - 05 - 流程控制
- Step into Kotlin - 12 - Object 与枚举
- Step into Kotlin - 18 - Extension 与 this
- Kotlin在Android工程中的应用
- 如何初步搭建Spring的运行环境
- mysql语法、特殊符号及正则表达式的使用
- 在Fragment里面使用ExpandableListView实现仿qq好友列表
- 音频信号处理——音频矢量化
- Step into Kotlin - 09 - 集合
- UI基础之 UIview
- .gitignore文件通用模板
- IOS实现单例模式的几种实现方法
- 通知中心
- 光照
- 对ansys主要命令的解释
- IOS 数据存储之 FMDB 详解
- 使用Kotlin开发Android应用(I):简介