Encode URL in Java

Syntax

URLEncoder.encode(String s,String enc)

Example:

URLEncoder.encode("http://example.com/page.html?params=@@@/", StandardCharsets.UTF_8.toString())

Result:

http%3A%2F%2Fexample.com%2Fpage.html%3Fparams%3D%40%40%40%2F


Decode URL in Java

Syntax

URLDecoder.decode(String s,String enc)

Example:

URLDecoder.decode("http%3A%2F%2Fexample.com%2Fpage.html%3Fparams%3D%40%40%40%2F", StandardCharsets.UTF_8.toString())

Result:

http://example.com/page.html?params=@@@/