Arguments
Learn how Kotlin provides support for using default and named arguments.
Default arguments
Kotlin allows us to provide function parameters with a default value, which is used if the corresponding argument is omitted on the call.
fun String.splitString(separator: Char = ',')
When splitting a string with the extension function above (more on extension functions later), we can choose any separator. However, thanks to the default value “,
” we can also omit it, if the “,
” is actually what we need:
Get hands-on with 1400+ tech skills courses.