对数组进行各种 *** 作

对数组进行各种 *** 作,第1张

概述//: Playground - noun: a place where people can play import UIKit //声明、定义数组 var numbers = [1, 1, 2, 3, 5, 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

总结

以上是内存溢出为你收集整理的对数组进行各种 *** 作全部内容,希望文章能够帮你解决对数组进行各种 *** 作所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1086875.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存