pasring a queryString

Hi,
I would like to parse a query String below into a map, is there any java api method i can use to parse the string? I am doing the parsing in my Servlet Class.
The String:
"firstName=Raoul&latName=Brooks&birthDay=05/16/1980&IP=127.0.1&email=rBrooks@yahoo.com"
komlaaaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

colr__Commented:
use String[] result = theMainString.split("&"); to extract the individual name=value pairts, then use String[] result = theBitString.split("="); on each of the individual elements to parse the name and value.

colr__

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
fargoCommented:
There is no direct way, but may be u can use the following.

    /**
     * Parses the query and string the parameters in the hashmap
     */
    private void parseQuery(String query)
    {
        // check if query exists
        if (query == null || query.length() == 0)
            return;

        // creating a tokenizer
        StringTokenizer tokenizer = new StringTokenizer(query, "&");

        // iterate over tokens
        while (tokenizer.hasMoreTokens())
        {
            // getting the next parameter
            String parameter = tokenizer.nextToken();

            // getting delimiter index
            int equalIdx = parameter.indexOf("=");

            // get name
            String name = parameter.substring(0, equalIdx);

            // get value
            String value = parameter.substring(equalIdx + 1);

            // add new parameter
            hashMap.put(name,value);
        }
    }

init the hashmap in your class.

fargoCommented:
ah..colr__ sorry...i also answered the same...the only difference is my method.

didn't refresh it on time.
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

rrzCommented:
I don't know if you will find this easier but here is another way.  
  Map paramMap = request.getParameterMap();  
But getting the values out is more work because the values are stored as String arrays.  
  String firstName = ((String[])paramMap.get("firstName"))[0];
  String lastName = ((String[])paramMap.get("lastName"))[0];
dear_sweet_udayCommented:
Hi
     you can use request.getParameterNames() Its of Enumeration type
 
   Code Below :>

  java.util.Enumeration e = request.getParameterNames();

   while (e.hasMoreElements())
  {

        String key = (String)e.nextElement();
        String[] values = request.getParameterValues(key);
   }

 Its simple to use
rrzCommented:
dear,  the question was  
>I would like to parse a query String below into a map
dear_sweet_udayCommented:
Yup
  but Enumeration gives you name & value both
  & Map requires Name & value pair ............so you can do that conversion
rrzCommented:
Yeah, your right.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.