加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

对数组进行各种操作

发布时间:2020-12-14 02:04:15 所属栏目:百科 来源:网络整理
导读://: Playground - noun: a place where people can play import UIKit // 声明、定义数组 var numbers = [ 1 , 2 ,216)">3 ,216)"> 5 ,216)">8 ] var strings = [ "ios" , "android" , "java" ] // 数组长度 numbers . count strings . count // 向数组中添

//: Playground - noun: a place where people can play


import UIKit


//声明、定义数组

var numbers = [1, 2,216)">3,216)"> 5,216)">8]

var strings = ["ios","android","java"]

//数组长度

numbers.count

strings.count

//向数组中添加元素

//向数组中追加元素

numbers.append(13)

strings.append("javascript")

//直接向数组后面添加一个数组

numbers += [21,216)">34]

strings += ["jquery","C#"]

//使用index索引添加元素

numbers.insert(-0)

strings.insert("apple",216)">0)

//删除数组中得元素

numbers.removeAtIndex(0)

numbers

strings.removeAtIndex( strings

//删除数组中最后一个元素

numbers.removeLast()

strings.removeLast()

strings

//使用enumerate

for (index,item) in enumerate(numbers) {

println("(index):(item)")

}

for item in enumerate(strings) {

println("index:(item.0),:(item.1)")

}

//创建数组

var nums = [Int]()

class Admin {

}

var student = [Admin]()

//创建指定大小数组

var num2 = [Int](count: 5,repeatedValue: 3)

//数组的赋值和拷贝行为

var num3 = [2,216)"> 3,216)">4,216)"> 5]

var num4 = num3

num3[1] = 100

num3

num4

//

var num5 = num3

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读