Java tutorial
//package com.java2s; import java.util.Locale; public class Main { private static String encodingUrl(String url) { final char[] specChars = { '+', ':' }; String header; String body; if (url.startsWith("https://")) { header = "https://"; } else if (url.startsWith("http://")) { header = "http://"; } else { header = ""; } body = url.substring(header.length()); for (char specChar : specChars) { String encodedStr = encodingSpecUrlChar(specChar); body = body.replace("" + specChar, encodedStr); } return header + body; } private static String encodingSpecUrlChar(char c) { int asciiCode = (int) c; String hexStr = Integer.toHexString(asciiCode).toUpperCase(Locale.ENGLISH); if (hexStr.length() < 2) { hexStr = "0" + hexStr; } String result = "%" + hexStr; return result; } }