今天突然要用到for循环的中止,这个真的极少用,第一个就想到了break,但我也不确定,之后写了个测试代码,果然是这样,看来还是要多巩固基础啊
下面是测试代码类:(里面的东西是根据项目的业务逻辑出来的命名)
1 public class TestForBreak {
2
3 /**
4 * @param args
5 */
6 public static void main(String[] args) {
7 String file_url_param = "location,id";
8 String request_param = "id,taskId,romArchive,arcId,docState";
9 String file_url_params[] = file_url_param.split(",");
10 String request_params[] = request_param.split(",");
11 int file_url_params_size = file_url_params.length;
12 int request_params_size = request_params.length;
13 String file_url_param_name = "";
14 String request_param_name = "";
15 for(int i = 0 ; i < file_url_params_size ; i++){//附件链接的参数循环
16 file_url_param_name = file_url_params[i];
17 int flag = 0;//跳出外层循环的标识
18 for(int j = 0 ; j < request_params_size ; j++){//整个链接的参数循环
19 request_param_name = request_params[j];
20 if(file_url_param_name.equals(request_param_name)){//如果名称相同,则取对应参数的值,即:取id的值
21 file_url_param_name = request_param_name;
22 flag = 1;
23 break;//跳出第一层循环
24 }
25 }
26 if(flag == 1){
27 break;//跳出第二次循环
28 }
29 }
30 System.out.println("相等的内容:"+file_url_param_name);
31 }
32 }