StringUtils { public static String normalizeIdString(String idString) { final StringBuilder normalizedString = new StringBuilder(); idString.trim() .chars() .forEach(charInt -> { if (RESERVED_CHARACTERS.contains(charInt)) { normalizedString.append("_").append(charInt).append("_"); } else { normalizedString.append((char) charInt); } }); return normalizedString.toString(); }  static String normalizeIdString(String idString);  }
@Test public void testNormalizeIdString() { System.out.println("normalizeIdString"); String idString = "a!b*c\\d(e)f; g:h@i&j=k+l$m,n/o?p#q[r]s"; String expResult = "a_33_b_42_c\\d_40_e_41_f_59__32_g_58_h_64_i_38_j_61_k_43_l_36_m_44_n_47_o_63_p_35_q_91_r_93_s"; String result = StringUtils.normalizeIdString(idString); assertEquals(expResult, result); }