I was just experimenting with the
String.split
functionality and came across this situation which made me curious. I found that running this:
"hello".split("")
produces this
["", "h", "e", "l", "l", "o", ""]
. I didn’t expect for there to be empty strings on the start and end of the returned list only that the list would be made up of each character from the original string. To clarify, I’m not asking about the best way to iterate characters in a string or how to get them into a list, just curious about the implementation of
split
with an empty separator and why the empty strings were appended to each end of the resulting list?