java循环,字符串拼写

StringBuffer sb=new StringBuffer();
		Map<String,String> map=new HashMap<String,String>();
		map.put("key1","1" );
		map.put("key2","2" );
		map.put("key3","3" );
		map.put("key4","4" );
		Set<String> keys=map.keySet();
		for(Iterator<String> i = keys.iterator(); i.hasNext();){
			String key=i.next();
			String value=map.get(key);
			sb.append(key);
			sb.append("=");
			sb.append(value);
			sb.append("&");
		}
		
		if(sb.charAt(sb.length()-1)=='&'){
			sb.deleteCharAt(sb.length()-1);
		}
		System.out.println(sb.toString());

你可能感兴趣的:(java)