I want to know how I can convert one string or a String Object in a String array
using kotlin.
I made some research and found this JAVA code which seems to do what I need.
public static void main(String[] args) {
String word="abc";
String[] array = new String[word.length()];
for(int i = 0; i < word.length(); i++)
{
array[i] = String.valueOf(word.charAt(i));
}
for(String a:array){
System.out.println(a);
}
}
I expect to have something like this or better than it in Kotlin.
Thanks in advance.
Something like this:
val str = "abcd"
val array: Array<String> = str.toCharArray().map { it.toString() }.toTypedArray()
Try This:
val str = "Hello"
val arr = str.split("")
fun main() {
println(arr) // [, H, e, l, l, o]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With