- Learn Kotlin Programming(Second Edition)
- Stephen Samuel Stefan Bocutiu
- 192字
- 2021-06-24 14:13:26
Arrays
In Kotlin, we can create an array by using the arrayOf() library function:
val array = arrayOf(1, 2, 3)
Alternatively, we can create Array from an initial size and a function, which are used to generate each element:
val perfectSquares = Array(10, { k -> k * k })
Unlike Java, arrays are not treated as special by the language, and are a regular collection classes. Instances of arrays provide an iterator function and a size function, as well as a get and a set function. The get and set functions are also available through bracket syntax, like many C-style languages:
// Pull the first and second array value into variables
val element1 = array[0] val element2 = array[1]
// Set the second array item value to 5 array[2] = 5
To avoid boxing types that will ultimately be represented as primitives in the JVM, Kotlin provides alternative array classes that are specialized for each of the primitive types. This allows performance-critical code to use arrays as efficiently as they would do in plain Java. The provided classes are ByteArray, CharArray, ShortArray, IntArray, LongArray, BooleanArray, FloatArray, and DoubleArray.
- C# 7 and .NET Core Cookbook
- ClickHouse性能之巔:從架構設計解讀性能之謎
- Essential Angular
- Java Web應用開發技術與案例教程(第2版)
- 你必須知道的204個Visual C++開發問題
- Learning ELK Stack
- BIM概論及Revit精講
- 快人一步:系統性能提高之道
- TMS320LF240x芯片原理、設計及應用
- 詳解MATLAB圖形繪制技術
- Emgu CV Essentials
- Raspberry Pi Robotic Projects
- 讀故事學編程:Python王國歷險記
- Visual FoxPro程序設計實驗教程
- 數據庫技術及應用教程上機指導與習題(第2版)