简单的几行代码,大家说说优化思路
String tmpParam = "";for(String key : map.keySet()){ tmpParam += ("&" + key + "=" + URLEncoder.encode(map.get(key)));}tmpParam = tmpParam.substring(1);//去掉最前端的& String strUrl = "http://" + host + ":8080/smsControl/" + action + ".action?" + tmpParam;
public class Test02 { public static void main(String[] args) { final int count = 100000; long time01 = System.currentTimeMillis(); String s = ""; for (int i = 0; i < count; i++) { s += 'a'; } long time02 = System.currentTimeMillis(); System.out.println("String:" + (time02 - time01) + "ms"); long time03 = System.currentTimeMillis(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < count; i++) { sb.append('a'); } long time04 = System.currentTimeMillis(); System.out.println("StringBuilder:" + (time04 - time03) + "ms"); }}
[解决办法]