Here you can find the source of encodeURIComponent(String input)
public static String encodeURIComponent(String input)
//package com.java2s; //License from project: Apache License import java.io.UnsupportedEncodingException; import java.net.URLEncoder; public class Main { public static String encodeURIComponent(String input) { try {// w w w. j a va2 s . c om return URLEncoder.encode(input, "UTF-8").replaceAll(" ", "%20").replaceAll("!", "%21") .replaceAll("'", "%27").replaceAll("\\(", "%28").replaceAll("\\)", "%29") .replaceAll("\\+", "%2B").replaceAll("\\:", "%3A").replaceAll("~", "%7E"); } catch (UnsupportedEncodingException e) { } return null; } }