当前位置: 首页 > news >正文

湛江网站设计软件建设英文网站的公司

湛江网站设计软件,建设英文网站的公司,北京到安阳的高铁,wordpress轻社交集合有助于数据分组#xff0c;方便后续操作 集合类型说明Lists有序的可重复的集合Sets无序的不可重复的集合Maps键值对映射集合#xff0c;键唯一#xff0c;且一个键只能映射到一个值 每个集合类型都可以是可变的或者只读的 List List按照添加的顺序存储内容#xff…集合有助于数据分组方便后续操作 集合类型说明Lists有序的可重复的集合Sets无序的不可重复的集合Maps键值对映射集合键唯一且一个键只能映射到一个值 每个集合类型都可以是可变的或者只读的 List List按照添加的顺序存储内容并允许重复 存储的内容通常称作元素 List类型 创建只读List使用listOf()方法 创建可变List使用mutableListOf()方法 在创建列表时Kotlin可以推断存储项的类型。可以在列表声明后的尖括号中添加类型来显式声明类型 fun main() {val readOnlyShapes listOf(triangle, square, circle)println(readOnlyShapes) // [triangle, square, circle]val shapes: MutableListString mutableListOf(triangle, square, circle)println(shapes) // [triangle, square, circle]shapes[2] circle2// shapes[3] circle3 // Index 3 out of bounds for length 3println(shapes) // [triangle, square, circle2] }操作MutableList索引不能超过初始长度 为了防止不必要的修改你可以通过将可变列表赋值给List来获得它们的只读视图 fun main() {val shapes: MutableListString mutableListOf(triangle, square, circle)val shapesLocked: ListString shapes }这种方式通常叫做铸造casting List常用方法 查看List方法 获取元素 fun main() {val readOnlyShapes listOf(triangle, square, circle)println(The first item in the list is: ${readOnlyShapes[0]}) // The first item in the list is: triangleprintln(The first item in the list is: ${readOnlyShapes.first()}) // The first item in the list is: triangleprintln(The last item in the list is: ${readOnlyShapes.last()}) // The last item in the list is: circle }获取长度 fun main() {val readOnlyShapes listOf(triangle, square, circle)println(This list has ${readOnlyShapes.count()} items) // This list has 3 items } 判断是否包含某一元素 fun main() {val readOnlyShapes listOf(triangle, square, circle)println(circle in readOnlyShapes) // true }新增和删除 fun main() {val shapes: MutableListString mutableListOf(triangle, square, circle)// 添加 pentagonshapes.add(pentagon)println(shapes) // [triangle, square, circle, pentagon]// 删除第一个 pentagonshapes.remove(pentagon)println(shapes) // [triangle, square, circle] }Set Set集合中存储的数据无序并且不能重复 Set类型 创建只读Set使用setOf()方法 创建可变Set使用MutableList()方法 fun main() {val readOnlyFruit setOf(apple, banana, cherry, cherry)val fruit: MutableSetString mutableSetOf(apple, banana, cherry, cherry) }Set常用方法 获取元素 因为Set为无序集合所以不能通过索引获取集合元素 fun main() {val set setOf(apple, banana, cherry, cherry)println(The first item in the set is: ${set.first()}) // The first item in the set is: appleprintln(The last item in the set is: ${set.last()}) // The last item in the set is: cherry }Map Map以键值对的形式存储数据。你可以通过引用键来访问值 键是唯一的如果插入重复键则会覆盖之前的值 Map类型 要创建只读Map使用mapOf()函数 要创建可变地图MutableMap使用mutableMapOf()函数 在创建Map时kotlin可以推断出存储的元素类型。要显式声明类型可以在Map声明后的尖括号中添加键和值的类型。例如MutableMapString, Int。键的类型为String值的类型为Int fun main() {val readOnlyJuiceMenu mapOf(apple to 100, kiwi to 190, orange to 100)println(readOnlyJuiceMenu) // {apple100, kiwi190, orange100}val juiceMenu: MutableMapString, Int mutableMapOf(apple to 100, kiwi to 190, orange to 100)println(juiceMenu) // {apple100, kiwi190, orange100} }常用方法 获取数据 使用键获取值 fun main() {val readOnlyJuiceMenu mapOf(apple to 100, kiwi to 190, orange to 100)println(readOnlyJuiceMenu[apple]) // 100 }获取所有的键或者值 fun main() {val readOnlyJuiceMenu mapOf(apple to 100, kiwi to 190, orange to 100)println(readOnlyJuiceMenu.keys) // [apple, kiwi, orange]println(readOnlyJuiceMenu.values) // [100, 190, 100] }获取键值对数量 fun main() {val readOnlyJuiceMenu mapOf(apple to 100, kiwi to 190, orange to 100)println(readOnlyJuiceMenu.count()) // 3 }修改/删除 fun main() {val juiceMenu: MutableMapString, Int mutableMapOf(apple to 100, kiwi to 190, orange to 100)juiceMenu.put(coconut, 150) // 添加键coconut和值 150println(juiceMenu) // {apple100, kiwi190, orange100, coconut150}juiceMenu.put(apple, 200) // 修改coconut的值成 200println(juiceMenu) // {apple200, kiwi190, orange100, coconut150}juiceMenu.remove(orange) // 删除orangeprintln(juiceMenu) // {apple200, kiwi190, coconut150} }是否包含某元素 是否包含某个键 fun main() {val readOnlyJuiceMenu mapOf(apple to 100, kiwi to 190, orange to 100)println(readOnlyJuiceMenu.containsKey(kiwi)) // trueprintln(orange in readOnlyJuiceMenu.keys) // true }是否包含某个值 fun main() {val readOnlyJuiceMenu mapOf(apple to 100, kiwi to 190, orange to 100)println(200 in readOnlyJuiceMenu.values) // false }
http://www.sczhlp.com/news/178736/

相关文章:

  • 长沙做网站公司在电脑上怎么建设网站
  • 如何做网站推广 求指点wordpress插件升级
  • 无形资产 网站开发网页制作入门基础教程
  • 怎么制做网站淮南市招标投标信息网
  • 盐城市建设局网站设计备案资料网站建设 电脑 手机
  • 台州企业网站seo免费做 爱视频网站
  • 正规建网站企业建设网站企业网银登录
  • 东莞家用台灯东莞网站建设高级网页设计师培训班
  • 网站免费模版代码建设工程信息网为官方网站
  • 做旅游地产的网站和公司杭州外贸网站建设公司价格
  • 鹤壁建设网站推广渠道家居网站建设公司
  • 怎么学习制作网站轻松筹网站可以做吗
  • 大学网站建设工作总结售后服务网点建设是指网站
  • PWN手的成长之路-13-jarvisoj_level0
  • 计算机毕设 java 基于 Java 的题库管理强大的系统 基于 SSM+JavaWeb 的题库全流程管理平台 Java+MySQL 的题库服务一体化系统
  • 微信最新协议API上线!个人号快速接入
  • 网站整站百度推广建设网站是不是合发
  • 网站源码使用方法家具设计软件
  • 阿里云网站服务器企业网站开发计划
  • 网站开发设计的论文php购物网站开发设计与实现
  • 免费单页网站建设王也踏青图是哪一集
  • 建设网站的意义知乎图片在线生成器
  • 长沙app开发费用长沙seo关键词排名优化
  • 自己建设购物网站电脑优化大师
  • 顺德公司网站制作网站开发的软件支持
  • 北京专业响应式网站建设人才网站开发方案
  • php制作网站用什么软件删除wordpress首页链接
  • 化工网站建站模板禅城网站建设公司
  • 黑龙江网站建设企业挂网站需要什么服务器
  • 山东兴润建设集团网站模板手机网站建设多少钱