Java tutorial
//package com.java2s; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; public class Main { public static String encode(String val) { try { return URLEncoder.encode(val, "UTF-8").replace("+", "%20"); } catch (UnsupportedEncodingException e) { return val; } } }