Java URL Encode encode(String s)

Here you can find the source of encode(String s)

Description

URL Encodes the given String s using the UTF-8 character encoding.

License

Open Source License

Parameter

Parameter Description
s a String

Return

url encoded string

Declaration

public static String encode(String s) 

Method Source Code

//package com.java2s;
import java.io.UnsupportedEncodingException;

import java.net.URLEncoder;

public class Main {
    /**//from   ww  w.  j  av  a  2s . c  om
     * URL Encodes the given String <code>s</code> using the UTF-8 character encoding.
     *
     * @param s a String
     * @return url encoded string
     */
    public static String encode(String s) {
        if (s == null)
            return null;
        try {
            return URLEncoder.encode(s, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            // utf-8 always available
        }
        return null;
    }
}

Related

  1. encode(String raw)
  2. encode(String s)
  3. encode(String s)
  4. encode(String s)
  5. encode(String s)
  6. encode(String s)
  7. encode(String s)
  8. encode(String s, String enc)
  9. encode(String s, String encoding)