String#split with a "dot"

String#split with a dot "." does return an empty array:


    String packages[] = "com.airhacks".split(".");
    assertThat(packages.length, is(0));

The split method parameter is a regular expression, and "dot" is Any character (may or may not match line terminators)

Escaping the dot solves the "problem":


    String packages[] = "com.airhacks".split("\\.");
    assertThat(packages.length, is(2));

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
...the last 150 posts
...the last 10 comments
License