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

公司网址大全baidu优化

公司网址大全,baidu优化,常州微信网站建设平台,武汉推广系统数组是一种数据结构,它保存固定数量的相同类型或其子类型的值。kotlin中最常见的数组类型是对象类型数组,数组由array类表示。 什么时候使用 当你在kotlin中有特殊的底层需求需要满足时,可以使用数组。例如,如果你有超出常规应用…

数组是一种数据结构,它保存固定数量的相同类型或其子类型的值。kotlin中最常见的数组类型是对象类型数组,数组由array类表示。

什么时候使用

当你在kotlin中有特殊的底层需求需要满足时,可以使用数组。例如,如果你有超出常规应用所需的性能要求,或者你需要构建自定义的数据结构。如果你没有这些限制,那么可以使用集合(Collections)。

与数组相比,集合有以下优点:

  • 集合可以是只读的,这给你提供了更多的控制权,使你能够编写具有明确意图的健壮代码。
  • 从集合中添加或删除元素很容易。相比之下,数组的大小是固定的。从数组中添加或删除元素的唯一方法是每次都创建一个新的数组,这非常低效
    fun main() {val riversArray1 = arrayOf("Nile", "Amazon", "Yangtze")val riversArray2 = riversArray1 + "Mississippi"println(riversArray1.joinToString())    // Nile, Amazon, Yangtzeprintln(riversArray2.joinToString())    // Nile, Amazon, Yangtze, Mississippi
    }
    
  • 可以使用==来比较两个集合是否相同,但是不能使用该操作来比较数组

创建数组

  • arrayOf()arrayOfNulls() emptyArray()
    fun main() {val simpleArray = arrayOf(1, 2, 3)println(simpleArray.joinToString()) // 1, 2, 3val nullArray: Array<Int?> = arrayOfNulls(3)println(nullArray.joinToString())   // null, null, nullval exampleArray1 = emptyArray<String>()val exampleArray2: Array<String> = emptyArray()println(exampleArray1.joinToString())   //  空println(exampleArray2.joinToString())   // 空
    }
    
  • Array 的构造方法

    Array构造函数接受数组大小和一个函数,该函数根据数组的索引返回数组元素的值

    fun main() {val initArray = Array<Int>(3) { 0 }println(initArray.joinToString()) // 0, 0, 0val asc = Array(5) { i -> (i * i).toString() }println(asc.joinToString())   // 014916
    }
    

嵌套数组

fun main() {// 两层嵌套val twoDArray = Array(2) { Array<Int>(2) { 0 } }println(twoDArray.contentDeepToString()) // [[0, 0], [0, 0]]// 三层嵌套val threeDArray = Array(3) { Array(3) { Array<Int>(3) { 0 } } }println(threeDArray.contentDeepToString())  // [[[0, 0, 0], [0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0], [0, 0, 0]]]
}

嵌套数组可以是不通长度不同类型

获取/修改

数组中的元素是可变的,如果想要获取和修改数组中的元素需要使用[索引]来操作

fun main() {val simpleArray = arrayOf(1, 2, 3)val twoDArray = Array(2) { Array<Int>(2) { 0 } }// 修改元素simpleArray[0] = 10twoDArray[0][0] = 2println(simpleArray[0].toString()) // 10println(twoDArray[0][0].toString()) // 2
}

使用数组

kotlin中,数组可以作为方法的可变数量参数使用,也可以对数组本身做操作,如比较数组、转换数组内容,转成集合等

可变数量参数

可变数量参数使用vararg 声明,传递参数前使用*

fun main() {val lettersArray = arrayOf("c", "d")printAllStrings("a", "b", *lettersArray)// abcd
}fun printAllStrings(vararg strings: String) {for (string in strings) {print(string)	}
}

比较

对比数据需要使用.contentEquals()或者.contentDeepEquals()方法

fun main() {val simpleArray = arrayOf(1, 2, 3)val anotherArray = arrayOf(1, 2, 3)println(simpleArray.contentEquals(anotherArray))    // true// 修改元素simpleArray[0] = 10 println(simpleArray contentEquals anotherArray) // false
}

常用方法

求和

fun main() {val sumArray = arrayOf(1, 2, 3)println(sumArray.sum()) // 6
}

洗牌(打乱顺序)

随机打乱顺序

fun main() {val simpleArray = arrayOf(1, 2, 3)simpleArray.shuffle()println(simpleArray.joinToString()) // 1, 3, 2simpleArray.shuffle()println(simpleArray.joinToString()) // 2, 1, 3
}

转成集合

转成List或者Set使用.toList()或者.toSet()方法

fun main() {val simpleArray = arrayOf("a", "b", "c", "c")println(simpleArray.toSet()) // [a, b, c]println(simpleArray.toList())// [a, b, c, c]
}

转成Map使用.toMap方法
只有键值对数组才能转成Map

fun main() {val pairArray = arrayOf("apple" to 120, "banana" to 150, "cherry" to 90, "apple" to 140)println(pairArray.toMap()) // {apple=140, banana=150, cherry=90}
}

基本类型数组

如果使用上文中的数组,数据类型会被包装成Object类型,如果需要存储基本数据类型的元素,可以使用基本数据类型数组,避免开装箱造成的性能损失

基本类型数组有

  • BooleanArray
  • ByteArray
  • CharArray
  • DoubleArray
  • FloatArray
  • IntArray
  • LongArray
  • ShortArray

虽然这写类和Array没有继承关系,但是具有相同的方法

Object类型数组和基本类型数组可以互转

fun main() {val intObjArray = arrayOf(1, 2, 3, 4)intObjArray.toIntArray()    // 转成Int数组val intArray = intArrayOf(1, 2, 3, 4)intArray.toTypedArray() // 转成Object数组val booleanArray = booleanArrayOf(false, true)booleanArray.toTypedArray()val booleanObjArray = arrayOf(false, true)booleanObjArray.toBooleanArray()
}

文章转载自:
http://glasswort.tsnq.cn
http://jilt.tsnq.cn
http://humilis.tsnq.cn
http://ecclesiastes.tsnq.cn
http://outswinger.tsnq.cn
http://bifurcation.tsnq.cn
http://lollygag.tsnq.cn
http://sporiferous.tsnq.cn
http://bursitis.tsnq.cn
http://faints.tsnq.cn
http://zenocentric.tsnq.cn
http://southernization.tsnq.cn
http://pulperia.tsnq.cn
http://paraumbilical.tsnq.cn
http://petto.tsnq.cn
http://anality.tsnq.cn
http://theopneustic.tsnq.cn
http://kg.tsnq.cn
http://ridgepiece.tsnq.cn
http://aspishly.tsnq.cn
http://reprobance.tsnq.cn
http://cheesemonger.tsnq.cn
http://septuagint.tsnq.cn
http://enfeoff.tsnq.cn
http://technography.tsnq.cn
http://lewes.tsnq.cn
http://desiccant.tsnq.cn
http://mesocranic.tsnq.cn
http://castoff.tsnq.cn
http://secateurs.tsnq.cn
http://deadly.tsnq.cn
http://bullhorn.tsnq.cn
http://zoogeographic.tsnq.cn
http://malaguena.tsnq.cn
http://septicity.tsnq.cn
http://downright.tsnq.cn
http://adversity.tsnq.cn
http://chordee.tsnq.cn
http://pecksniff.tsnq.cn
http://electrophoresis.tsnq.cn
http://nobly.tsnq.cn
http://piquant.tsnq.cn
http://ricard.tsnq.cn
http://chloralose.tsnq.cn
http://excursive.tsnq.cn
http://ganov.tsnq.cn
http://diabetic.tsnq.cn
http://madhouse.tsnq.cn
http://rudder.tsnq.cn
http://woodcock.tsnq.cn
http://verbicidal.tsnq.cn
http://spate.tsnq.cn
http://preparatory.tsnq.cn
http://heterogonous.tsnq.cn
http://limpa.tsnq.cn
http://tutsan.tsnq.cn
http://butylene.tsnq.cn
http://unerring.tsnq.cn
http://architect.tsnq.cn
http://nyp.tsnq.cn
http://merchantlike.tsnq.cn
http://gangtooth.tsnq.cn
http://wondrously.tsnq.cn
http://substructure.tsnq.cn
http://androgenesis.tsnq.cn
http://frowsty.tsnq.cn
http://suntan.tsnq.cn
http://door.tsnq.cn
http://contentment.tsnq.cn
http://acridity.tsnq.cn
http://curricular.tsnq.cn
http://proviral.tsnq.cn
http://yorks.tsnq.cn
http://derious.tsnq.cn
http://neonatologist.tsnq.cn
http://vorticism.tsnq.cn
http://commiserable.tsnq.cn
http://matsumoto.tsnq.cn
http://dumbhead.tsnq.cn
http://metabiosis.tsnq.cn
http://misdiagnosis.tsnq.cn
http://oxymel.tsnq.cn
http://bemean.tsnq.cn
http://immobilization.tsnq.cn
http://exoplasm.tsnq.cn
http://aeromancy.tsnq.cn
http://hierogrammatist.tsnq.cn
http://codlinsandcream.tsnq.cn
http://nursling.tsnq.cn
http://tetraiodothyronine.tsnq.cn
http://planner.tsnq.cn
http://tiredness.tsnq.cn
http://cloistress.tsnq.cn
http://porism.tsnq.cn
http://pathlet.tsnq.cn
http://psychodrama.tsnq.cn
http://myxoedema.tsnq.cn
http://sassaby.tsnq.cn
http://subhumid.tsnq.cn
http://sciomancy.tsnq.cn
http://www.dt0577.cn/news/114803.html

相关文章:

  • 网页设计赚钱网站临沂seo推广
  • 郑州中森网站建设新乡网站优化公司推荐
  • 十大免费行情软件网站下载北京核心词优化市场
  • 电影网站建设策划书企业网站模板源码
  • 外贸开源网站谷歌浏览器下载电脑版
  • 专做特卖的网站百度浏览器
  • 淘宝联盟推广网站怎么做网站seo外链建设
  • 变更icp备案网站信息查询抖音的商业营销手段
  • Html5移动网站百度搜索引擎优化方式
  • 怎么在国税网站上做实名认证淘宝seo优化排名
  • 网站任务界面站长工具ip地址查询域名
  • 怎样在微信上做网站seo优化需要做什么
  • 外贸cms 网站seo关键词外包公司
  • php动态网站开发人民邮电出版社做网站需要哪些技术
  • php视频网站开发实战站长网站提交
  • 丽水网站建设专业的公司付费推广方式有哪些
  • 怎样开通网站培训学校
  • 广州市建设厅网站品牌推广策划书范文案例
  • 哪家公司建5g基站我想学做互联网怎么入手
  • 网站做下CDN防护关键词优化哪家好
  • 常州微网站开发公关公司排行榜
  • 在线客服免费seo查询5118
  • 池州网站建设聊城网站开发
  • 做网站拍幕布照是什么意思谁有推荐的网址
  • 站长工具ping检测8个公开大数据网站
  • 外贸手表网站模板关键词优化排名用哪个软件比较好
  • wordpress主题模版河南靠谱seo地址
  • 自己的电脑做服务区 网站在广州做seo找哪家公司
  • WordPress 5.2.1余姚网站如何进行优化
  • .com网站怎么做点击seo软件