Here you can find the source of encode(String string)
private static String encode(String string)
//package com.java2s; //License from project: Open Source License import java.io.UnsupportedEncodingException; import java.net.URLEncoder; public class Main { private static String encode(String string) { try {//from ww w.ja va 2 s . c om return URLEncoder.encode(string, "UTF-8").replaceAll("\\+", "%20"); } catch (UnsupportedEncodingException e) { return null; } } }