convert Query String To Properties - Java java.net

Java examples for java.net:URL Query

Description

convert Query String To Properties

Demo Code

//package com.java2s;
import java.util.Properties;

public class Main {
    public static void main(String[] argv) {
        String queryString = "&asdf=java2s.com";
        System.out.println(convertQueryStringToProperties(queryString));
    }//from w w  w.  j  av  a 2s.c om

    public static Properties convertQueryStringToProperties(
            String queryString) {
        if (queryString != null) {
            Properties prop = new Properties();
            String[] queryStringArray = queryString.split("&");
            for (int i = 0; i < queryStringArray.length; i++) {
                String[] avp = queryStringArray[i].split("=");
                if (avp.length == 2) {
                    prop.put(avp[0], avp[1]);
                }
            }

            return prop;
        } else {
            return null;
        }
    }
}

Related Tutorials