fun main(arg: Array<String>) {

    //可读写的集合创建

    val mutableListOf1 = mutableListOf<Int>(1, 2, 3)
val mutableListOf2 = mutableListOf<Int>() val mutableSetOf1 = mutableSetOf<Int>(11, 22, 33)
val mutableSetOf2 = mutableSetOf<Int>() val mutableMapOf1 = mutableMapOf<Int, String>(Pair(1, "name1"), Pair(2, "name2"))
val mutableMapOf2 = mutableMapOf<Int, String>() //可读不可写的集合创建
val listOf1 = listOf<Int>(1, 2, 3) val of1 = setOf<Int>(1, 2, 3) val mapOf1: Map<Int, String> = mapOf<Int, String>(Pair(11, "name11"), Pair(22, "name22")) //list集合遍历
println(" ---------------------------------mutableListOf -------------------------------------")
mutableListOf2.add(100)//添加数据
mutableListOf2.removeAt(0)//删除数据
for (i in mutableListOf1) {
if (i==1){ }
println(i)
}
println(" ------------------------------------listOf-----------------------------------------")
val get = listOf1.get(0)
println("索引0的值为"+get)
for (i in listOf1) {
println(i)
} println(" ---------------------------------------mutableSetOf---------------------------------")
mutableSetOf2.add(100)//添加数据
mutableSetOf2.remove(11)//删除数据
//set集合遍历
for (i in mutableSetOf1) {
println(i)
}
println(" -------------------------------------SetOf-----------------------------------") for (i in of1) {
println(i)
}
println(" ------------------------------mutableMapOf------------------------------------------") //map 集合遍历
for (entry in mutableMapOf1) {
println(entry)
}
println(" --------------------------------mutableMapOf----------------------------------------")
mutableMapOf2.put(3,"new name")
mutableMapOf2.remove(2)
for ((key, value) in mutableMapOf1) { println("key = $key value = $value")
}
println(" ------------------------------mapOf-------------------------------------------------") for (entry in mapOf1) {
println(entry)
}
println(" --------------------------------mapOf-----------------------------------------------") for ((key, value) in mapOf1) {
println("key = $key value = $value")
}
}
val toList = mutableListOf1.toList()//将可读写集合转为只读集合

kotlin中集合的更多相关文章

  1. Kotlin中功能操作与集合(KAD 11)

    作者:Antonio Leiva 时间:Feb 2, 2017 原文链接:https://antonioleiva.com/functional-operations-collections-kotl ...

  2. 初识Kotlin之集合

    Kotlin的集合是让我为之心动的地方,丰富的高阶函数帮助我们高效开发.今天介绍Kotlin的基础集合用法.获取集合元素的函数.过滤元素的函数.元素排序的函数.元素统计的函数.集合元素映射的函数.集合 ...

  3. 浅谈Kotlin中的函数

    本文首发于 vivo互联网技术 微信公众号 链接:https://mp.weixin.qq.com/s/UV23Uw_969oVhiOdo4ZKAw作者:连凌能 Kotlin,已经被Android官方 ...

  4. Kotlin中Range与异常体系剖析

    好用的集合扩展方法: 下面来看一下对于集合中好用的一些扩展方法,直接上代码: 如果我们想取出集合中的第一个值和最后一个值,用Java方式是get(0)和get(size-1),但是在Kotlin中提供 ...

  5. Kotlin中变量不同于Java: var 对val(KAD 02)

    原文标题:Variables in Kotlin, differences with Java. var vs val (KAD 02) 作者:Antonio Leiva 时间:Nov 28, 201 ...

  6. web项目中 集合Spring&使用junit4测试Spring

    web项目中 集合Spring 问题: 如果将 ApplicationContext applicationContext = new ClassPathXmlApplicationContext(& ...

  7. Java中集合List,Map和Set的区别

    Java中集合List,Map和Set的区别 1.List和Set的父接口是Collection,而Map不是 2.List中的元素是有序的,可以重复的 3.Map是Key-Value映射关系,且Ke ...

  8. .Net中集合排序的一种高级玩法

    背景: 学生有名称.学号, 班级有班级名称.班级序号 学校有学校名称.学校编号(序号) 需求 现在需要对学生进行排序 第一排序逻辑 按学校编号(序号)排列 再按班级序号排列 再按学生学号排列 当然,在 ...

  9. Python中集合set()的使用及处理

    在Python中集合(set)与字典(dict)比较相似,都具有无序以及元素不能重复的特点 1.创建set 创建set需要一个list或者tuple或者dict作为输入集合 重复的元素在set中会被自 ...

随机推荐

  1. graph Laplacian 拉普拉斯矩阵

    转自:https://www.kechuang.org/t/84022?page=0&highlight=859356,感谢分享! 在机器学习.多维信号处理等领域,凡涉及到图论的地方,相信小伙 ...

  2. jar下载及Maven配置整理

    Spring的各版本jar包下载地址http://repo.spring.io/release/org/springframework/spring/ springframework下载地址https ...

  3. Windows下快速启动/关闭orcl服务

    大家都知道windows下绝大部分都是图形操作化,很少用命令来执行,例如启动.关闭orcl数据库服务时,一般情况都是在任务管理器(taskmgr.ctrl+shift+esc)或服务(services ...

  4. 关于在window8上使用ssh命令的记录

    1.开启虚拟机以及git bash窗口,准备连接 2.在虚拟机中输入ifconfig -a查看虚拟机ip 从图中找到ip为 : inet 地址:192.168.78.133 3.输入命令: ssh r ...

  5. <a>标签的target 属性 全局作用

    局部(或全局)设置<a>标签的target属性           对于超链接<a>标签,target属性的设置是比较关键的,在不同的用户场景下选用适合的新页面载入方式,可以大 ...

  6. Install RabbitMQ on CentOS 7

    NOTE: this article is only for CentOS 7 How to Install RabbitMQ on CentOS 7 yum update Install erlan ...

  7. JavaScript展开操作符(Spread operator)介绍

    本文介绍JavaScript的展开操作符(Spread operator)....本文适合ES6初学者. 你可以通过展开操作符(Spread operator)...扩展一个数组对象和字符串.展开运算 ...

  8. mybatise 设置全局变量实例

    前言 在平时的工作中有时候是需要在配置文件中配置全局变量的,因为这些东西是不会变的,并且每个mapper都传参的话也显得有点繁琐,还好mybatis本身是支持全局变量的,今天工作中用到了,记录一下. ...

  9. Pytest命令行执行测试

    Pytest命令行执行测试 from collections import namedtuple Task = namedtuple('Task', ['summary','owner','done' ...

  10. spring replaced method 注入

           replaced method注入是spring动态改变bean里方法的实现.需要改变的方法,使用spring内原有其他类(需要继承接口org.springframework.beans ...