java - Problems with running String.split("") -


i have integer i'm trying convert string[] array, can access individual digits comprised of. here's code:

    integer num = 101;     string[] numarray = num.tostring().split(""); 

why system.out.println(numarray.length) return 4 not 3?

edit: to people downvoting thread, if read post, understand tried troubleshoot issue myself before posting here. there downvote trend here because of exams' week , people seeking easy answers, wasn't.

because ...

this method works if invoking two-argument split method given expression , limit argument of zero. trailing empty strings therefore not included in resulting array.

however, leading empty strings included. you're splitting on "nothing" matches before first character in string, leading empty string.

the same thing occur if had, example:

string foo = ":a:b:c:"; string[] bar = foo.split(":"); 

bar[0] empty string , bar.length 4


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -