StringUtils extends org.apache.commons.lang3.StringUtils { public static String doubleChar(final String str, final char c) { if (isEmpty(str)) { return str; } int start = 0; int end = str.indexOf(c, start); if (end == INDEX_NOT_FOUND) { return str; } final StringBuilder buf = new StringBuilder(str.length() + 1); do { end += 1; buf.append(str.substring(start, end)).append(c); start = end; end = str.indexOf(c, start); } while (end != INDEX_NOT_FOUND); buf.append(str.substring(start)); return buf.toString(); }  static String doubleChar(final String str, final char c); static String toAlphaNumeric(String text);  }
@Test @DisplayName("Doubling of characters") void doubleChar() { assertNull(StringUtils.doubleChar(null, 'a')); assertEquals("", StringUtils.doubleChar("", 'a')); assertEquals("b", StringUtils.doubleChar("b", 'a')); assertEquals("aa", StringUtils.doubleChar("a", 'a')); assertEquals("aaaa", StringUtils.doubleChar("aa", 'a')); assertEquals("baabaa", StringUtils.doubleChar("baba", 'a')); assertEquals("aabaab", StringUtils.doubleChar("abab", 'a')); }