code: public static String encodeURIPathComponent(String s) {
      StringBuilder result = new StringBuilder();
      for (int i = 0; i < s.length(); i++) {
        result.append(Char.encodeURIPathComponent(s.charAt(i)));
      }
      return (result.toString());
    }
docs: Encodes a char to percentage code, if it is not a path character in the sense of URIs