Kotlin String toByteArray Default Charset Is UTF-8

April 8, 2019
val bytes = "Hello".toByteArray()

same as

val bytes = "Hello".toByteArray(Charsets.UTF_8)

Source

fun String.toByteArray(
    charset: Charset = Charsets.UTF_8
): ByteArray
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.