数组
val c1 = intArrayOf(1,2,3,4,5)
val c2 = IntArray(5){it+1}
it:对应数组的下标
Log.i("shawn",c2.contentToString())//打印数组的内容
装箱数组
val c3 = arrayOf("123","456")
val c4 = arrayOf(Student(),Student())
遍历数组
val c1 = intArrayOf(1,2,3,4,5)
方式1:
for (a in c2){
print("输出$a")
}
方式2:
c2.forEach { a -> print(a) }
查询某一个元素是否在数组中
val c1 = intArrayOf(1,2,3,4,5)
var c2 = 1
if(c2 in c1){
print("$c2,存在数组中")
}
网友评论