Why does
int a = 1234;
String b = a + "";
String[] c = b.split("");
Result in:
c[0] = ""
c[1] = "1"
c[2] = "2"
c[3] = "3"
c[4] = "4"
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
String.splittakes a regular expression String as an argument. You have provided an empty regex, which matches the empty string. Thus, you get one empty string match from the start of the string and then every character split by an empty string. You should probably provide a valid regex.Ordinarily there would be an empty string at the end of the split, but Java intentionally excludes this from the array resulting from
.splitwith this one-argument usage.