jointUrl(String, Map) makes inefficient use of keySet iterator instead of entrySet iterator

错误提示:

 jointUrl(String, Map) makes inefficient use of keySet iterator instead of entrySet iterator

原因:

遍历HashMap时,遍历keySet返回的Key,再通过Key取得想要的Value;
这种遍历方式很低效。

原代码:

for (String key: params.keySet()) {
   url.append(key).append("=").append(params.get(key)).append("&");
}

修改代码:

for (Map.Entry entry: params.entrySet()) {
    url.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
}

你可能感兴趣的:(jointUrl(String, Map) makes inefficient use of keySet iterator instead of entrySet iterator)