zoukankan      html  css  js  c++  java
  • Swift 数组

    // 数组的用法

    let empetyArray = []  // 空数组

     

    let stringArray = [String]()  // 字符串数组,限定其值为字符串

     

    let intArray = [Int]()       // 整型数组,限定其值为整型

     

    var shoppingList = ["苹果","香蕉","西瓜","木瓜","黄瓜","冬瓜"] // 声明一个四个字符串的数组

     

    print(shoppingList.capacity)

     

     

    // 增加

    shoppingList.append("芒果")     // 方法一

     

    shoppingList += ["荔枝"];       // 方法二

     

    shoppingList.insert("橘子", atIndex: 0) // 方法三

     

    print(shoppingList)

     

    // 常用用法

    print(shoppingList.count)    // 数组中元素的个数

    print(shoppingList.capacity) // 数组的容量最大为12

    print(shoppingList.isEmpty// 判断数组是否为空

     

     

    // 修改

    shoppingList[1] = "哈密瓜"

    print(shoppingList)

     

    shoppingList[2...5] = ["Apples","Banans"// 把下标为2345的值改为 "Apples","Banans"

    print(shoppingList)

     

    // 删除

    shoppingList.removeLast()

    print(shoppingList)

     

    shoppingList.removeAtIndex(3)

    print(shoppingList)

     

    //shoppingList.removeAll()

    //print(shoppingList)

     

     

    // 数组的遍历

    for item in shoppingList

    {

        print(item)

    }

    1
  • 相关阅读:
    CENTOS7下安装REDIS
    Linux 查看端口状态netstat
    Centos7启动zookeeper无法连接2181端口
    企业信息化之路---集成
    Linux启动/停止/重启Mysql数据库的方法
    详解线程池
    详细的RocketMQ说明
    2021面试题准备~~~
    Https原理详解
    es 常用DSL
  • 原文地址:https://www.cnblogs.com/fantasy3588/p/5068360.html
Copyright © 2011-2022 走看看