Java, how to split string and shift

How to split a string 2 characters and shift

My string is = todayiscold

My goals are: "to", "od", "Da", "ay", "Yi", "is", "SC", "CO", "ol", "LD"

But with this Code:

Arrays.toString("todayiscold".split("(?<=\\G.{2})")));

I get: "to", "LD"

Can I help you

Solution

Try this:

String e = "example";
        for (int i = 0; i < e.length() - 1; i++) {
            System.out.println(e.substring(i,i+2));
        }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>