Peculiar behavior of split() of string class

Joker :

To my understanding following program should print 0,0 as an output.

However, when I run this program I am getting 1,0 as an output.

public class Test1 {
    public static void main(String[] args) {
        System.out.println("".split(";").length); //1
        System.out.println(";".split(";").length);//0
    }
}

Please help me understand what is going on here ?

Scary Wombat :

relavant code

        // If no match was found, return this
        if (off == 0)
            return new String[]{this};

        // Add remaining segment
        if (!limited || list.size() < limit)
            list.add(substring(off, value.length));

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=442211&siteId=1