This week's book giveaways are in the Cloud and AI/ML forums. We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line! See this thread and this one for details.
You can step through each character in your string easily enough (String.toCharArray()) and build up your replacement String (using a StringBuilder, StringBuffer, new array of chars - whatever you like). If you ignore the hyphens you just need to chuck in a hyphen every five characters in your new string. If the strings are variable length you may have to do a little arithmetic up front to find out where this hyphen should be. A Map will hold your mapped key/value pair - just swap the old value with the value in the Map and append it to the new String.