Here you can find the source of encode(String s)
public static String encode(String s)
//package com.java2s; import java.io.*; import java.net.URLEncoder; public class Main { public static String encode(String s) { if (s == null) { return ""; }/*from w w w . jav a 2 s.c o m*/ try { return URLEncoder.encode(s, "UTF-8").replace("+", "%20") .replace("*", "%2A").replace("%7E", "~") .replace("#", "%23"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage(), e); } } }