2
String value = "good.day";
String splitValues[] = value.split(".");
System.out.println(splitValues.length);

The output of the above code is 0.I know that split method uses regex. So we have to use escape sequence "\" to make it work.But my question is why this output?. If . is a meta character which represents any character, we should get the length of the string as output isn't?

RamValli
  • 4,389
  • 2
  • 33
  • 45

1 Answers1

6

Remember when you split, the argument is removed. Thus, when all the characters are split, there are none remaining.

Malik Brahimi
  • 16,341
  • 7
  • 39
  • 70
  • 8
    This is halfway to a good answer. To earn my upvote, you need to point out that the `split` method explicitly discards trailing empty strings. – Dawood ibn Kareem Mar 05 '15 at 01:35