Kotlin Reference
Quick reference tables for Kotlin keywords, operators, and standard library.
Keywords
| Name | Description |
|---|
val | Read-only variable |
var | Mutable variable |
fun | Function declaration |
class | Class declaration |
object | Singleton object |
interface | Interface declaration |
when | Pattern matching expression |
is | Type check |
as | Type cast |
in | Range/collection membership, contravariance |
out | Covariance |
suspend | Mark suspendable function |
data | Auto-generate data class methods |
sealed | Restricted class hierarchy |
open | Allow class/method inheritance |
override | Override parent member |
lateinit | Delayed non-null initialization |
by | Delegation |
Null Safety Operators
| Name | Description |
|---|
?. | Safe call: returns null instead of throwing |
?: | Elvis: returns fallback if left is null |
!! | Not-null assertion: throws if null |
as? | Safe cast: returns null if cast fails |
Scope Functions
| Name | Description |
|---|
let | Execute block on nullable value, return block result |
run | Execute block on object, return block result |
with | Execute block on object (not extension), return result |
apply | Configure object, return the object itself |
also | Side effect on object, return the object itself |
Collection Functions
| Name | Description |
|---|
filter | Keep elements matching condition |
map | Transform each element |
flatMap | Transform and flatten |
reduce | Accumulate to single value |
fold | Like reduce but with initial value |
find | First matching element or null |
any | True if any element matches |
all | True if all elements match |
none | True if no elements match |
groupBy | Group elements by key |
sortedBy | Sort by selector |
zip | Pair elements from two collections |