Java tutorial
//package com.java2s; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; public class Main { private static String percentEncode(String s) throws UnsupportedEncodingException { if (s == null) { return ""; } return URLEncoder.encode(s, "UTF-8") // OAuth encodes some characters differently: .replace("+", "%20").replace("*", "%2A").replace("%7E", "~"); } }