I need to break this line:
00016282000079116050
He has predefined pieces. It should be like this:
00016 282 00 0079 116 050
I made this code:
String unformatted = String.valueOf("00016282000079116050");
String str1 = unformatted.substring(0,5);
String str2 = unformatted.substring(5,8);
String str3 = unformatted.substring(8,10);
String str4 = unformatted.substring(10,14);
String str5 = unformatted.substring(14,17);
String str6 = unformatted.substring(17,20);
System.out.println(String.format("%s %s %s %s %s %s", str1, str2, str3, str4, str5, str6));
This works, but I need to make this code more presentable / beautiful.
Something with Java threads or regex should be good. Any suggestions?
source
share