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

地方旅游网站模板百度推广账户优化方案

地方旅游网站模板,百度推广账户优化方案,饿了么网站做生鲜吗,wordpress建站教程网集合有助于数据分组,方便后续操作 集合类型说明Lists有序的可重复的集合Sets无序的不可重复的集合Maps键值对映射集合,键唯一,且一个键只能映射到一个值 每个集合类型都可以是可变的或者只读的 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: MutableList<String> = 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: MutableList<String> = mutableListOf("triangle", "square", "circle")val shapesLocked: List<String> = 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: MutableList<String> = mutableListOf("triangle", "square", "circle")// 添加 "pentagon"shapes.add("pentagon")println(shapes) // [triangle, square, circle, pentagon]// 删除第一个 "pentagon"shapes.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: MutableSet<String> = 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声明后的尖括号<>中添加键和值的类型。例如:MutableMap<String, Int>。键的类型为String,值的类型为Int

fun main() {val readOnlyJuiceMenu = mapOf("apple" to 100, "kiwi" to 190, "orange" to 100)println(readOnlyJuiceMenu)  // {apple=100, kiwi=190, orange=100}val juiceMenu: MutableMap<String, Int> = mutableMapOf("apple" to 100, "kiwi" to 190, "orange" to 100)println(juiceMenu)  // {apple=100, kiwi=190, orange=100}
}

常用方法

获取数据

使用键获取值

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: MutableMap<String, Int> = mutableMapOf("apple" to 100, "kiwi" to 190, "orange" to 100)juiceMenu.put("coconut", 150) // 添加键"coconut"和值 150println(juiceMenu) // {apple=100, kiwi=190, orange=100, coconut=150}juiceMenu.put("apple", 200) // 修改"coconut"的值成 200println(juiceMenu) // {apple=200, kiwi=190, orange=100, coconut=150}juiceMenu.remove("orange")    // 删除"orange"println(juiceMenu)  // {apple=200, kiwi=190, coconut=150}
}

是否包含某元素

是否包含某个键

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.15wanjia.com/news/27813.html

相关文章:

  • 培训网站系统建设方案百度seo培训公司
  • 网站开发方向学啥怎样做一个产品营销方案
  • 零基础网站建设视频教程优化公司排名
  • 如何用服务器搭建网站网站构建的基本流程
  • 让做网站策划没经验怎么办西安seo排名
  • 南京做网站公司地点网站建设制作过程
  • 医院网站建设需要多少钱免费网站推广网站破解版
  • wordpress防站seo技术外包
  • 企业百度推广济南seo培训
  • 龙岩全网搜系统开发谷歌seo排名工具
  • 固定ip做网站和域名区别网络营销怎么推广
  • 昆明做网站b站推广入口2023
  • 怎么自创网站电话销售如何快速吸引客户
  • 大连 做网站公司百度指数特点
  • 可不可以免费创建网站怎么网络推广自己业务
  • 商业网站建设试题每天三分钟新闻天下事
  • 在阿里云服务器做淘客网站站长之家seo工具
  • 微信推广小程序怎么做旺道seo网站优化大师
  • 400全国服务热线容桂网站制作网络小说排行榜
  • 网站评估内容 优帮云微信软文推广怎么做
  • 做外贸网站建设在线搜索资源
  • 外贸网站设计公司网站建设报价方案
  • 做网站一个月赚多少钱长春百度推广排名优化
  • 网站制作字怎么放在图上面app关键词排名优化
  • 国家企业营业执照查询系统河南关键词优化搜索
  • 外贸网站建设内容包括北京网站推广公司
  • 浙江建设三类人员证书查询百度seo培训课程
  • 做ar网站广东病毒感染最新消息
  • 中国人民银行官网登录入口全网优化哪家好
  • 国际电商平台排行榜seocms