You can even get the formatting you want using a one-liner, q.v. the code snippet below. I manually build the first three characters followed a dash. After this, I do a blanket replacement to insert dashes after each subsequent group of four characters at at time. My code assumes that your string is at least three characters long. If you have logic for what happens for strings less than three characters of length, then update your question with that information.
String str1 = "abc1234abcd1234abcd12";
str1 = str1.substring(0, 3) + "-" + str1.substring(3).replaceAll("(.{4})", "$1-");
System.out.println(str1);
Output:
abc-1234-abcd-1234-abcd-12
Demo here:
Rextester