URLDecoder

java.net.URLDecoder Example

URLDecoder is a utility class for HTML form decoding. This class contains static methods for decoding a String from the application/x-www-form-urlencoded MIME format.

Project Environment

This example was implemented using the following tools :

  • Eclipse 4.3 (Kepler)
  • JDK 1.4 or greater

1. Example of URLDecoder

We are going to decode string in this example. Create a java class named URLDecoderExample and paste the following code.

URLDecoderExample.java:

01
02
03
04
05
06
07
08
09
10
11
package com.example.javacodegeeks;
 
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
 
public class URLDecoderExample {
    public static void main(String args[])throws UnsupportedEncodingException
    {
        System.out.println(URLDecoder.decode("special+chars%3A+%26%25*+", "UTF-8"));
    }
}

In above example we are decoding string in UTF-8 format.

output:

1
special chars: &%*

Download the source code

This was an example of URLDecoder in Java.

Download
You can download the full source code of this example here:URLDecoderExample.zip
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

Vaibhav Kulkarni

Vaibahv is PH.D candidate and holds masters degree in computer application. He is active contributor to Apache Software Foundation as well as openJDK.
Subscribe
Notify of
guest


This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button