//数组声明 var arr0 = Array<Int>() var arr1 = Array<String>(count: 3, repeatedValue: "") var strs = ["Hello"] print(strs.count) //个数 strs.append("Hi") //添加 print(strs.isEmpty) //判空 strs.appendContentsOf(["How", "Are", "Your"]) //添加数组 strs.insert("Bob", atIndex: 0) //插入 strs.removeLast() print(strs) strs.removeFirst(2) //移除前几个 print(strs) strs.removeRange(strs.endIndex.advancedBy(-2) ..< strs.endIndex) //移除最后2个 print(strs) strs.removeAll(keepCapacity: true) //移除所有但保留存储空间 strs += ["a","b"] //数组合并 strs.description strs.debugDescription strs[0] = "WWW" //替换 strs.reserveCapacity(2) print(strs)
时间: 2024-10-12 20:22:25