convert Query String To String - Java java.net

Java examples for java.net:URL Query

Description

convert Query String To String

Demo Code

//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String queryString = "java2s.com";
        String lineBreak = "o";
        System.out.println(convertQueryStringToString(queryString,
                lineBreak));/*from w w  w . j  ava2  s  .c o m*/
    }

    public static String convertQueryStringToString(String queryString,
            String lineBreak) {
        StringBuffer sb = new StringBuffer();
        if (queryString != null) {
            String[] queryStringArray = queryString.split("&");
            for (int i = 0; i < queryStringArray.length; i++) {
                String[] avp = queryStringArray[i].split("=");
                if (avp.length == 2) {
                    sb.append(avp[0]);
                    sb.append(" : ");
                    sb.append(avp[1]);
                    sb.append(lineBreak);
                }
            }

            return sb.toString();
        } else {
            return null;
        }
    }
}

Related Tutorials