String pos_dm = "1,16,17";
String act_dm = "添加-1,删除-1,添加-16,删除-16,添加-17,删除-17,添加-18,删除-18,"; for(int i=0;i<pos.length;i++){
for(int j=0;j<act.length;j++){
String action = act[j].substring(0,act[j].indexOf("-"));
String module = act[j].substring(act[j].indexOf("-")+1, act[j].length());

if(pos[i].equals(module)){
System.out.println(pos[i]+"---"+action);
}else{
continue;
}
}
}
/*
打印如下:1---添加
1---删除
16---添加
16---删除
17---添加
17---删除
*//*
如果把上面的两个字符串改成这样:
String pos_dm = "1,16,17";
String act_dm = "添加-1,删除-1,添加-16,删除-16,";那么我就想让它打印如下:1---添加
1---删除
16---添加
16---删除
17---因为act_dm里没有17求解...谢谢!
*/     

解决方案 »

  1.   

    楼主你那代码太乱了吧 数组变量形式都不对帮你改了下String pos = {"1","16","17"};
    List posList = new ArrayList();
    String act = {"添加-1","删除-1","添加-16","删除-16","添加-17","删除-17","添加-18","删除-18"};        for(int i=0;i<pos.length;i++){
                for(int j=0;j<act.length;j++){
                    String action = act[j].substring(0,act[j].indexOf("-"));
                    String module = act[j].substring(act[j].indexOf("-")+1, act[j].length());
                    
                    if(pos[i].equals(module)){
                        posList.add(pos[i]);
                        System.out.println(pos[i]+"---"+action);
                    }else{
                        System.out.println(pos[i]+"---");
                        continue;
                    }
                }
            }
         
      

  2.   


    String pos_dm = "1,16,17";
    String act_dm = "添加-1,删除-1,添加-16,删除-16,";
            String[] pos = pos_dm.split(",");
            String[] act = act_dm.split(",");        for(int i=0;i<pos.length;i++){
             boolean a = false;
                for(int j=0;j<act.length;j++){
                    String action = act[j].substring(0,act[j].indexOf("-"));
                    String module = act[j].substring(act[j].indexOf("-")+1, act[j].length());
                    
                    if(pos[i].equals(module)){
                     a = true;
                        System.out.println(pos[i]+"---"+action);
                    }else{
                        continue;
                    }
                }
                if(!a){
                 System.out.println(pos[i]+"---");
                }
            }
    }
      

  3.   


    唉...没办法,前台传过来的字符串是用","分割的.但你给的代码数组定义的不对...
    应该是下面这样:String pos = {"1","16","17"};
    //改成
    String[] pos = {"1","16","17"};
    还有就是你的代码没有实现我要的功能...
    是我没有描述清楚么?/*
    String pos_dm = "1,16,17";
    String act_dm = "添加-1,删除-1,添加-16,删除-16,添加-17,删除-17,添加-18,删除-18,添加-19,删除-19";
    //打印如下:
    1---添加
    1---删除
    16---添加
    16---删除
    17---添加
    17---删除
    17---删除如果把上面的两个字符串改成这样:
    String pos_dm = "1,16,17,18,19,20";
    String act_dm = "添加-1,删除-1,添加-16,删除-16,";那么我就想让它打印如下:1---添加
    1---删除
    16---添加
    16---删除
    17---
    18---
    19---
    20---不知道这样的理解没有?
    */
      

  4.   

    for(int i=0;i<pos.length;i++){
                boolean isHave = false ;
                for(int j=0;j<act.length;j++){
                    String action = act[j].substring(0,act[j].indexOf("-"));
                    String module = act[j].substring(act[j].indexOf("-")+1, act[j].length());
                    
                    if(pos[i].equals(module)){
                        System.out.println(pos[i]+"---"+action);
                        isHave = true;
                        break;
                    }
                }
                if( !isHave ){
                  System.out.println(pos[i]+"---")
                }
            }
      

  5.   

    String[] poss = pos_dm.split(",");
    String[] acts = act_dm.split(",");
    for(int i=0;i<pos.length;i++){
     String pos = poss[i];
     for(int j=0;j<acts.length;j++){
     String act = acts[j];
     String[] acs = act.split("-")
     if(acs[1].equals(pos)){
       system.out.println(pos+"---"acs[0]);
    }
    }
    }