If you are sure that you will always have input in the same format, you can just use StringBuilderand do something like this:
String input = "12345678";
String output = new StringBuilder().append(input.substring(0, 4))
.append(".").append(input.substring(4, 6)).append(".")
.append(input.substring(6)).toString();
System.out.println(output);
This code creates a new line by adding dots to the substrings in the specified places.
Conclusion:
1234.56.78
source
share