Here you can find the source of urlEncode(String str)
public static String urlEncode(String str)
//package com.java2s; //License from project: Apache License public class Main { public static String urlEncode(String str) { if (str == null) return null; StringBuffer tmp = new StringBuffer(); for (int i = 0; i < str.length(); ++i) { char a = str.charAt(i); if (((a < ':') && (a > '/')) || ((a < '[') && (a > '@')) || ((a < '{') && (a > '`')) || (a == '_')) tmp.append(a);//from ww w . j av a 2 s . co m else if (a < '\16') tmp.append("%0" + Integer.toHexString(a)); else tmp.append("%" + Integer.toHexString(a)); } return tmp.toString(); } }