Java examples for java.lang:String Unicode
Return an encoded String for url from value
//package com.java2s; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; public class Main { public static void main(String[] argv) throws Exception { String value = "java2s.com"; System.out.println(urlEncode(value)); }/*from w w w. j a va 2 s .c o m*/ /** * Return an encoded String for url from value * @param value string to encode * @return encoded string */ public static String urlEncode(String value) { if (value == null) return value; try { return URLEncoder.encode(value, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return null; } } }