Sample program:
[java]
package com.ngdeveloper.com;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
public class ComparePrintandSystem {
static String intro="I am naveen kumar working @ www.ngdeveloper.com";
public static void main(String[] args) throws UnsupportedEncodingException {
System.out.println(URLEncoder.encode(intro,"UTF-8"));
}
}
[/java]
Output:
I+am+naveen+kumar+working+%40+www.ngdeveloper.com
URLEncoder Rules:
All the characters (a to z & A to Z) and numbers (0 to 9) remains same.
Space is converted to “+”
All the other characters are converted to hexadecimal values by prefixing with %.
In the above sample program, %40 is the hexadecimal value for @ sign.
Thanks for reading this post……………….!!!