Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert encoded email address in Java?

Tags:

java

If I receive an emailAddress in the following format:

example%40gmail.com

In Java how do I convert it to this:

[email protected]
like image 999
Starus Avatar asked Jul 25 '26 22:07

Starus


2 Answers

Use URLDecoder.decode(String s, String enc) becuase URLDecoder.decode(String s) is deprecated in Java 1.5.

Here is the code to test your case:

@Test
public void testUrlDecoder() throws UnsupportedEncodingException {
    String encodedStr = "example%40gmail.com";
    String decodedStr = URLDecoder.decode(encodedStr, "UTF-8");
    assertEquals("[email protected]", decodedStr);
}
like image 115
Alfredo Osorio Avatar answered Jul 27 '26 13:07

Alfredo Osorio


See the answer to this question: Java: How to unescape HTML character entities in Java?

like image 43
Naftali Avatar answered Jul 27 '26 11:07

Naftali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!