Create query URL from map - Android java.net

Android examples for java.net:URL

Description

Create query URL from map

Demo Code

import android.content.Context;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.widget.TextView;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

public class Main{

    public static String makedburlstr(String url, Map<String, ?> params) {
        Object[] keys = params.keySet().toArray();
        Arrays.sort(keys);//ww  w .  ja  va 2s . co  m
        StringBuffer sb = new StringBuffer();
        StringBuffer urlbuff = new StringBuffer(url + "?");
        for (Object s : keys) {

            if (null == params.get(s)) {

            } else {
                sb.append(s);
                sb.append(params.get(s));
                urlbuff.append(s)
                        .append("=")
                        .append(URLEncoder.encode(params.get(s).toString()))
                        .append("&");
            }
        }
        return urlbuff.toString();

    }

}

Related Tutorials