主题:java中这句for代码怎么理解?
public static String doPost(String urlString, Map[color=FF00FF]<String, String> [/color]nameValuePairs)
throws IOException{
URL url = new URL(urlString);
URLConnection connection = url.openConnection();
connection.setDoOutput(true); //允许输出数据
PrintWriter out = new PrintWriter(connection.getOutputStream());
boolean first = true;
[color=FF0000] for (Map.Entry<String, String> pair : nameValuePairs.entrySet())[/color]{
if (first) first = false;
else out.print('&');
String name = pair.getKey();
String value = pair.getValue();
out.print(name);
out.print('=');
out.print(URLEncoder.encode(value, "GB2312")); //请求正文采用GB2312编码
}
我想问问大家红色地方怎么理解呀?这个for语句怎么不像其它的for(;;;)呀?
throws IOException{
URL url = new URL(urlString);
URLConnection connection = url.openConnection();
connection.setDoOutput(true); //允许输出数据
PrintWriter out = new PrintWriter(connection.getOutputStream());
boolean first = true;
[color=FF0000] for (Map.Entry<String, String> pair : nameValuePairs.entrySet())[/color]{
if (first) first = false;
else out.print('&');
String name = pair.getKey();
String value = pair.getValue();
out.print(name);
out.print('=');
out.print(URLEncoder.encode(value, "GB2312")); //请求正文采用GB2312编码
}
我想问问大家红色地方怎么理解呀?这个for语句怎么不像其它的for(;;;)呀?