Languages
[Edit]
EN

Java - encodeURIComponent() equivalent like in JavaScript

10 points
Created by:
Root-ssh
178170

In this article, we would like to show how to get JavaScript encodeURIComponent() function equivalent in Java.

Using Java, sometimes it is necessary to encode some data to send inside URL. JavaScript provides well known encodeURIComponent() function.

To get the same effect in Java it is necessary to do the following code:

Output:

 

Note: check decodeURIComponent function Java equivalent here.

 

Reusable code example

Edit

URIEncoder.java file:

Program.java file:

Output:

 

Optimal solution

Edit

Multiple replaceAll() calls in the above examples require multiple iterations through the encoded string.

In this section, you can find the optimal solution.

 

See also

Edit
  1. Java - decodeURIComponent equivalent in JavaScript 
  2. JavaScript - encode / escape URL characters

Alternative titles

  1. Java - encode URI component function equivalent like in JavaScript
  2. JavaScript encodeURIComponent() equivalent in Java
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join