Reputation: 3539
I want to split a string to single characters. So I do:
"abcd".split("");
But this yields:
["", "a", "b", "c", "d"]
The first empty string is not something I'm used to when doing the same in other languages (e.g. Ruby). What is the logic behind it?
Upvotes: 2
Views: 1827
Reputation: 5661
Why are you using String.split()
for this? You might be better served using String.toCharArray()
.
I know one will return you an array of Strings while the other will give you an array of chars. Since you want each character separately, I am assuming this doesn't matter to your code.
Upvotes: 4