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(Properties prop)
encode
try {
    StringBuffer sb = new StringBuffer();
    Enumeration e = prop.keys();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        String value = prop.getProperty(key);
        String ekey = URLEncoder.encode(key, "utf-8");
        String evalue = URLEncoder.encode(value, "utf-8");
...
Stringencode(String _string, String _sEncoding)
Encodes the string into URL format.
try {
    return URLEncoder.encode(_string, _sEncoding);
} catch (Exception ex) {
    throw new RuntimeException("failed to encode string into URL format using encoding " + _sEncoding, ex);
Stringencode(String from, String to, String word)
encode
return String.format(Locale.UK,
        "https://translate.googleapis.com/translate_a/single?client=gtx&sl=%s&tl=%s&dt=t&q=%s", from, to,
        URLEncoder.encode(word));
Stringencode(String in)
encode
try {
    return URLEncoder.encode(in, "UTF-8").replace("+", "%20").replace("*", "%2A").replace("%7E", "~");
} catch (Exception wontHappen) {
    return null;
Stringencode(String input)
encode
try {
    return URLEncoder.encode(input, systemEncoding).replace("+", "%20"); 
} catch (UnsupportedEncodingException e) {
    throw new RuntimeException(e);
Stringencode(String input)
* Returns a URL encoded String obtained from input, which is assumed to be a String composed of characters in the default charset.
String encoded = input;
try {
    encoded = URLEncoder.encode(input, getCharset());
} catch (Exception ex) {
    ex.printStackTrace();
return encoded;
Stringencode(String raw)

Encode the message by replacing all the white spaces with %20.

String encoded = null;
try {
    encoded = URLEncoder.encode(raw.replaceAll(" ", "%20"), "UTF-8");
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
return encoded;
Stringencode(String s)
encode
String ret = s;
try {
    ret = URLEncoder.encode(s.trim(), "UTF-8");
} catch (Exception localException) {
return ret;
Stringencode(String s)
URL encodes the specified string using the UTF-8 character encoding.
try {
    return (s != null) ? URLEncoder.encode(s, "UTF-8") : null;
} catch (UnsupportedEncodingException uee) {
    throw new RuntimeException("UTF-8 is unknown in this Java.");
Stringencode(String s)
Translates a string into x-www-form-urlencoded format.
final StringBuffer out = new StringBuffer(s.length());
final ByteArrayOutputStream buf = new ByteArrayOutputStream(32);
final OutputStreamWriter writer = new OutputStreamWriter(buf);
for (int i = 0; i < s.length(); i++) {
    int c = s.charAt(i);
    if (charactersDontNeedingEncoding.get(c)) {
        out.append((char) c);
    } else {
...