adam bien's blog

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));