Q:

Split a string after each two characters

I want to split a string after each two characters.  
For Example:
String aString= "abcdef"

I want to have after a split "ab cd ef"
How can i do it? 
Thanks :)

A:

Use regex:
        String str= "abcdef";

        String[] array=str.split("(?<=\\G.{2})");

        System.out.println(java.util. Arrays.toString(array));       

Output:

[ab, cd, ef]

A:

If you want the output to be the same string with extra spaces, you can simply use:
String newString = aString.replaceAll("(..)", "$1 ")

A:

This negative looakahead based regex should work for you:
String repl = "abcdef".replaceAll("..(?!$)", "$0 ");

PS: This will avoid appending space after last match, so you get this output:
"ab cd ef"

instead of:
"ab cd ef "

