code: public static String encodeHex(String s) {
      StringBuilder result = new StringBuilder();
      for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        if (isAlphanumeric(c)) result.append(c);
        else result.append(Integer.toHexString(s.charAt(i)).toUpperCase());
      }
      return (result.toString());
    }
docs: Replaces special characters in the string by hex codes (cannot be undone)