• [Kotlin] Array List ArrayList


    Array is mutable, but fixed length. Which means you can modify items in the Array, but you cannot add / remove item;

        // Array is fixed length, you cannot add or remove item
        val ary: Array<String> = arrayOf("Wan", "Zhen", "Tian")
        ary[1] = "gg"
        println(ary.contains("gg")) // true
        val mixedAry = arrayOf("Zhen", 23, true)
        val numAry: IntArray = intArrayOf(1,2,3) // doubleArrayOf ...
        val states = arrayOf("NIVDA", "APPLA")
        val allStates = states + ary // concat Array of string
        println(allStates.size) // 5

    List is immutable, you cannot reassign value for list itenm ,you cannot add / remove item;

        val list: List<String> = listOf("Wan", "Zhen", "Tian")
        // list[0] = "gg" // ERROR:: List is immutable
        val list2: List<String> = listOf("Wan2", "Zhen2", "Tian2")
        val allList = list + list2
        println(allList.size) // 6
        println(allList.isEmpty()) // false
        println(allList.contains("Wan")) // true

    ArrayList is mutable, you can add / remove itmes from ArrayList:

        // arrayList is mutatable
        val aryList = arrayListOf("Wan", "Zhen", "Tian")
        aryList.add("Josh")
        aryList.add(1, "Jack")
        println(aryList) // [Wan, Jack, Zhen, Tian, Josh]
        println(aryList.remove("Wan")) // true
        val subList = aryList.subList(1, 2)
        println(subList) // ["Jack"]
  • 相关阅读:
    Java 多线程之CyclicBarrier
    数据库事务隔离级别
    Java SE之Map接口
    (二)Shiro之一些重要的组件和工具类
    (一)Shiro之简介
    Datatables后端分页
    Spring之BeanFactory中Bean的生命周期
    Servlet之生命周期
    设计模式之单例设计模式
    day041 前端HTML CSS基本选择器(未整理完毕)
  • 原文地址:https://www.cnblogs.com/Answer1215/p/13798953.html
Copyright © 2020-2023  润新知