public static Hashtable<String,Object> parseQuery(String query,boolean keepDuplicates) throws URISyntaxException {
  if (query == null) {
    return null;
  }
  Hashtable<String,Object> parameters=new Hashtable<String,Object>();
  List<NameValuePair> nvps=parseQueryOrdered(query);
  Iterator<NameValuePair> i=nvps.iterator();
  while (i.hasNext()) {
    NameValuePair nvp=i.next();
    if (parameters.containsKey(nvp.getName())) {
      if (keepDuplicates == true) {
        Object v=parameters.get(nvp.getName());
        if (v instanceof String) {
          parameters.put(nvp.getName(),new String[]{(String)v,nvp.getValue()});
        }
 else {
          int size=((String[])v).length;
          String array[]=new String[size + 1];
          System.arraycopy(v,0,array,0,size);
          array[size]=nvp.getValue();
          parameters.put(nvp.getName(),nvp.getValue());
        }
      }
    }
 else {
      parameters.put(nvp.getName(),(nvp.getValue() == null) ? String.valueOf(true) : nvp.getValue());
    }
  }
  return parameters;
}

public static Hashtable < String , Object > parseQuery ( String query , boolean keepDuplicates ) throws URISyntaxException { if ( query == null ) { return null ; } Hashtable < String , Object > parameters = new Hashtable < String , Object > ( ) ; List < NameValuePair > nvps = parseQueryOrdered ( query ) ; Iterator < NameValuePair > i = nvps . iterator ( ) ; while ( i . hasNext ( ) ) { NameValuePair nvp = i . next ( ) ; if ( parameters . containsKey ( nvp . getName ( ) ) ) { if ( keepDuplicates == true ) { Object v = parameters . get ( nvp . getName ( ) ) ; if ( v instanceof String ) { parameters . put ( nvp . getName ( ) , new String [ ] { ( String ) v , nvp . getValue ( ) } ) ; } else { int size = ( ( String [ ] ) v ) . length ; String array [ ] = new String [ size + 1 ] ; System . arraycopy ( v , 0 , array , 0 , size ) ; array [ size ] = nvp . getValue ( ) ; parameters . put ( nvp . getName ( ) , nvp . getValue ( ) ) ; } } } else { parameters . put ( nvp . getName ( ) , ( nvp . getValue ( ) == null ) ? String . valueOf ( true ) : nvp . getValue ( ) ) ; } } return parameters ; }
parse the query string into an unordered map of name / value pairs . if keepduplicates parameter is true , then the resulting map will contain values of string object when only one occurrence of a key is found in the query , and an ordered list object if more than one occurrence is found , where the list is in the order of which they key occurred in the query . if keepduplicates parameter is false , all values will be strings , and only the first occurrence of the key will be kept .
