- Hello World
- println: 文字列表示後に改行される
- print: 文字列を表示する
- variables
- val: read-only
- var: mutable
- print variable:
- println("it's $variable")
- println("it's ${variable + 1}")
- 型推論あり
- Basic types
- Collections
- each collection type can be mutable or read-only
- casting is supported
- Control flow
- if, when
- range
1..4
,1..<4
,4 downTo 1
,1..5 step 2
- for, while(do-while)
- Functions
- Classes
- Null safety
For more information on basic types and their properties, see Basic types.
Category | Basic types |
---|---|
Integers | Byte, Short, Int, Long |
Unsigned integers | UByte, UShort, UInt, ULong |
Floating-point numbers | Float, Double |
Booleans | Boolean |
Characters | Char |
Strings | String |
Collection Type | Description |
---|---|
Lists | Ordered collections of items |
Sets | Unique unordered collections of items |
Maps | Sets of key-value pairs where keys are unique and map to only one value |
To prevent unwanted modifications, you can obtain read-only views of mutable lists by assigning them to a List:
val shapes: MutableList<String> = mutableListOf("triangle", "square", "circle")
val shapesLocked: List<String> = shapes