Java Utililty Methods URL Encode

List of utility methods to do URL Encode

Description

The list of methods to do URL Encode are organized into topic(s).

Method

Stringencode(String string)
encode
try {
    return URLEncoder.encode(string, "UTF-8").replaceAll("\\+", "%20");
} catch (UnsupportedEncodingException e) {
    return null;
Stringencode(String strInput)
Encode URL string by method URLEncoder.encode() - after this encoding all spaces will be encoded as + character.
String strEncoded = URLEncoder.encode(strInput, "UTF-8");
return strEncoded.replaceAll("\\+", "%20");
Stringencode(String text)
Encode text as UTF-8
return URLEncoder.encode(text, "UTF-8");
Stringencode(String toBeEncoded, String charSet, String defaultReturnValue)
encode
String encodedString;
try {
    encodedString = URLEncoder.encode(toBeEncoded, charSet);
} catch (Exception var5) {
    System.err.println(String.format("Error when url-encode:%s with charset:%s",
            new Object[] { toBeEncoded == null ? "" : toBeEncoded, charSet == null ? "" : charSet }));
    var5.printStackTrace();
    encodedString = defaultReturnValue;
...
Stringencode(String value)
encode
String encoded = null;
try {
    encoded = URLEncoder.encode(value, "UTF-8");
} catch (UnsupportedEncodingException ignore) {
StringBuilder buf = new StringBuilder(encoded.length());
char focus;
for (int i = 0; i < encoded.length(); i++) {
...
Stringencode(String value)
encode
if (value != null) {
    return URLEncoder.encode(value, "utf8");
} else {
    return "";
Stringencode(String value)
encode
if (isEmpty(value)) {
    return "";
try {
    value = java.net.URLEncoder.encode(value, "utf-8");
} catch (Exception ex) {
    ex.printStackTrace();
return value;
Stringencode(String value)
URL encodes a value using the UTF-8 charset
return URLEncoder.encode(value, "UTF-8");
Stringencode(String value, String charset)
encode
String result = null;
if (!isEmpty(value)) {
    try {
        result = URLEncoder.encode(value, charset);
    } catch (IOException e) {
        throw new RuntimeException(e);
return result;
Stringencode(String value, String encoding)
Translates a string into application/x-www-form-urlencoded format using a specific encoding scheme.
String encodedValue = null;
try {
    encodedValue = URLEncoder.encode(value, encoding);
} catch (Exception e) {
    throw new IllegalArgumentException(e.getMessage());
return encodedValue;