当前位置:网站首页>Kotlin study notes
Kotlin study notes
2022-08-08 20:31:00 【Do not forget the original intention z】
The course of Kotlin from Xiaobai to entering the pit
Record your learning journey from today:kotlin
Today's date is 2019.4.21. This is the first time I write a blog since learning programming. Although it is a personal idle note, it is just to deepen my understanding of programming. And understanding of programming
Today I learned arrays from kotlin. If I have misunderstandings about these, I hope God can point them out so that I can improve them
Three basic properties of arrays: consistency, order, immutability
Three ways to create an array of objects in Kotlin
arrayOf(vararg elements:T) where vararg indicates that the parameter is variable
arrayOfNulls<>(size:int) specifies the size of the array and creates an array with elements <>. Specifically because T<> cannot be writtenEnter it, so forgive me.
array(size:int,init:(int)->T) constructor, specify the size of the array through size. init is a function to initialize elements, we generally use Lambda expressions later
For specific usage, we check the following code:
fun main(args: Array) {
//Static initialization
val intArray1 = arrayOf(21,23,24)
//Dynamic initialization
val strArray = arrayOfNulls(4)
//Initialize the elements of the array
strArray[0] = "Zhang Fei"
strArray[1] = "Guan Yu"
strArray[2] = "Liu Bei"
strArray[3] = "Liu Guan Zhang"
// strArray[4] = "subscript out of bounds"/because the array length is specified. So immutable -> prompt error. subscript out of bounds
//traverse string array
for (item in strArray.indices){
println(strArray[item])
}
val intArray2=Array(10){i->i + i}
// Traverse the intArray array
for (item in intArray2){
println(item)
}
}
The problem we often encounter: subscript out of bounds:Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
This is the end of today's study. I hope I can continue to write the article on CSDN and cheer for myself!!
边栏推荐
- 梅科尔工作室OpenHarmony设备开发培训笔记-第一章学习笔记
- 1259 Alice and Bob
- 梅科尔工作室OpenHarmony设备开发培训笔记-第六章学习笔记
- OpenEuler's Ways to Improve Resource Utilization 02: Effects under Typical Applications
- leveldb-impl:level0
- IJCAI 2022 | 图神经网络可以检测到异常吗?
- 阿里云OSS文件下载到本地指定文件有坑
- CVPR 2022 ActivityNet竞赛冠军:中科院深圳先进院提出高低分双模态行为识别框架
- 书法家唐效奇
- 分门别类输入输出,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang基本数据类型和输入输出EP03
猜你喜欢
随机推荐
箭头函数this指向的解释
图的几种存储方式
新库上线 | CnOpenData信息传输、软件和信息技术服务业工商注册企业基本信息数据
fillder4 keeps prompting the system proxy was changed, watch me solve it
“12306” 的架构到底有多牛逼?
瑞吉外卖项目实战Day06--手机端
SushiSwap「SUSHI」下降了 93%,但还没有完全消失
NAACL2022 NER SOTA - RICON study notes
分门别类输入输出,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang基本数据类型和输入输出EP03
学习笔记:线性表的顺序表示和实现(二级指针实现)
什么是仿射函数?
idea 引入包报错:Unable to provision, see the following errors
稀疏矩阵转置--C语言
Redis布隆过滤器
【翻译】用Argo CD揭开企业规模的持续交付的秘密成分
劳务派遣业务流程图
一文教你普罗米修斯Prometheus的基础应用
深度学习初步认知
C语言关键字入门 这一篇足矣
五大理由告诉你为什么开发人员选择代码质量静态分析工具Klocwork来实现软件安全