In Java, you can convert a string into an array of its constituent bytes by calling myString.getBytes()
.
What's the equivalent of this in Kotlin?
In Java, you can convert a string into an array of its constituent bytes by calling myString.getBytes()
.
What's the equivalent of this in Kotlin?
Use the extension String.toByteArray()
- which means you will write myString.toByteArray()
. Note it defaults to UTF-8 encoding, but you can override this by providing an additional argument.
String.encodeToByteArray()
–
Inchon © 2022 - 2024 — McMap. All rights reserved.