HashMap的使用

package com.org.test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/***
 * @Author:liangjilong
 * @Date:2014-5-19
 * @Version:1.0
 */
public class Test1 {

	public static void main(String[] args) {
		Map<String, String> params = new HashMap<String, String>();
		params.put("key1", "values1");
		params.put("key2", "values2");
		params.put("key3", "values3");
		params.put("key4", "values4");
		params.put("key5", "values5");

		List<String> keys = new ArrayList<String>(params.keySet());
		String prestr = "";
		for (int i = 0; i < keys.size(); i++) {
			String key = keys.get(i);
			String value = params.get(key);

			if (i == keys.size() - 1) {// 拼接时,不包括最后一个&字符
				prestr = prestr + key + "=" + value;
			} else {
				prestr = prestr + key + "=" + value + "&";
			}
		}

		System.out.println(prestr);

	}

}

 

package com.org.test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/***
 * @Author:liangjilong
 * @Date:2014-5-19
 * @Version:1.0
 */
public class Test2 {

	public static void main(String[] args) {
		Map<String, String> params = new HashMap<String, String>();
		params.put("key1", "values1");
		params.put("key2", "values2");
		params.put("key3", "values3");
		params.put("key4", "values4");
		params.put("key5", "values5");


        Map<String, String> result = new HashMap<String, String>();

      
        for (String key : params.keySet()) {
            String value = params.get(key);
            if (value == null || value.equals("") || key.equalsIgnoreCase("sign")
                || key.equalsIgnoreCase("sign_type")) {
                continue;
            }
           // result.put(key, value);
            
            System.out.println(key+"="+value);
        }
        
          
		

	}

}

 

你可能感兴趣的:(HashMap)