Java, How to split String with shifting

java, regex, split, string

Solution

Try this:

        String e = "example";
        for (int i = 0; i < e.length() - 1; i++) {
            System.out.println(e.substring(i, i+2));
        }

Problem

How can I split a string by `2` characters with `shifting`. For example; My string is = `todayiscold` My target is: `"to","od","da","ay","yi","is","sc","co","ol","ld"` but with this code: ``` Arrays.toString("todayiscold".split("(?<=\\G.{2})"))); ``` I get: `"to","da","yi","co","ld" anybody helps?

Original source