Java URL Build buildQuery(Map params)

Here you can find the source of buildQuery(Map params)

Description

build Query

License

Apache License

Declaration

public static String buildQuery(Map<String, String> params) throws UnsupportedEncodingException 

Method Source Code

//package com.java2s;
/**// w  ww .j a  v a  2s . c o  m
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.UnsupportedEncodingException;

import java.net.URLEncoder;
import java.util.Map;

public class Main {
    public static String buildQuery(Map<String, String> params) throws UnsupportedEncodingException {
        StringBuilder sb = new StringBuilder();

        boolean first = true;
        for (Map.Entry<String, String> param : params.entrySet()) {
            if (!first) {
                sb.append("&");
            }
            sb.append(URLEncoder.encode(param.getKey(), "UTF-8")).append("=")
                    .append(URLEncoder.encode(param.getValue(), "UTF-8"));
            first = false;
        }

        return sb.toString();
    }
}

Related

  1. buildQuery(final Map query)
  2. buildQuery(final Map query)
  3. buildQuery(Map paramMap)
  4. buildQuery(Map paramMap)
  5. buildQuery(Map query)
  6. buildQueryString(Map parameters)
  7. buildQueryString(Map params)
  8. buildQueryString(Map queryParams)
  9. buildQueryString(Map params)