简体   繁体   中英

Java split string on empty delimiter returns empty string at the beginning?

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 (eg Ruby). What is the logic behind it?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM