code: public static String urlEncode(String strIn) {
          // Null begets null.
          if (strIn == null) {
              return null;
          }
  
          try {
              return URLEncoder.encode(strIn, "UTF-8");
          } catch (UnsupportedEncodingException e) {
              // This should never happen since UTF-8 always exists.
              throw new IllegalArgumentException("UTF-8");
          }
      }
docs: Encode the given string by replacing characters not legal in URLs with the
  appropriate escape sequences. For example "A B" becomes "A%20B". If a null string
  is passed, the result is null. This method calls URLEncoder.decode("UTF-8", strIn),
  which converts non-ASCII characters to UTF-8 sequences and then escapes the UTF-8
  sequences. It also converts spaces into '+' signs.
  
  @param  strIn    Input string to encode.
  @return          URL-encoded version of the same string, or null if strIn is null.
  @see             #urlDecode(String)