Sample code for 30+ languages & platforms
Java

URL Encoding and Decoding

Demonstrates URL encoding/decoding using the HTTP convenience methods.

Chilkat Java Downloads

Java
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    CkHttp http = new CkHttp();

    String s = "Hello World! 100% sure.";

    String encoded = http.urlEncode(s);
    System.out.println("URL encoded: " + encoded);

    //  Space → %20
    //  ! → %21
    //  % → %25

    String decoded = http.urlDecode(encoded);
    System.out.println("URL decoded: " + decoded);

    //  Output:

    //  URL encoded: Hello%20World%21%20100%25%20sure.
    //  URL decoded: Hello World! 100% sure.
  }
}