java split() returns additional empty value

?

-

why does the split, for instance "x:x:x".split("x"), returns

""
":"
":"

what's with the empty first record?
 
J

JScoobyCed

- said:
why does the split, for instance "x:x:x".split("x"), returns

""
":"
":"

what's with the empty first record?

The String "" is the first String of "x:x:x" terminated by "x" (see
Javadoc about String.split(String, int) )
 
N

Nigel Wade

- said:
why does the split, for instance "x:x:x".split("x"), returns

""
":"
":"

what's with the empty first record?

Because there is an implicit empty string before the first delimiter. The
trailing empty string is not included.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top