private List<String> getCjList(){
String cj1 = manufacturer1.getText();
String cj2 = manufacturer2.getText();
String cj3 = manufacturer3.getText();
String cj4 = manufacturer4.getText();
String cj5 = manufacturer5.getText();
String cj6 = manufacturer6.getText();
String cj7 = manufacturer7.getText();
String cj8 = manufacturer8.getText();
String cj9 = manufacturer9.getText();
String cj10 = manufacturer10.getText();
List<String> cjList = new ArrayList<String>();
int i = 1;
while(i > 0 && i < 11){
String cj = "cj";
if(!(cj + i).equals("")){
cjList.add(cj + i);
log.debug("++++++++++++++++++++++++++++++++++++++++=cj " + (cj + i) );
}
i++;
}
return cjList;
}
我想把变量cj1到cj10中不为空的存入cjList,可是存入的确是字符串“cj1”到 “cj10”。请哪位兄台指点一二。

解决方案 »

  1.   


    private List<String> getCjList(){
    String cj1 = manufacturer1.getText();
    String cj2 = manufacturer2.getText();
    String cj3 = manufacturer3.getText();
    String cj4 = manufacturer4.getText();
    String cj5 = manufacturer5.getText();
    String cj6 = manufacturer6.getText();
    String cj7 = manufacturer7.getText();
    String cj8 = manufacturer8.getText();
    String cj9 = manufacturer9.getText();
    String cj10 = manufacturer10.getText();
    List<String> cjList = new ArrayList<String>();
    int i = 1;
    while(i > 0 && i < 11){
    String cj = "cj";
    if(!(cj + i).equals("")){
    cjList.add(cj + i);
    log.debug("++++++++++++++++++++++++++++++++++++++++=cj " + (cj + i) );
    }
    i++;
    }
    return cjList;
    }
      

  2.   

    把你的cj1,cj2...这一堆String放数组里.比如cjArray[]中.从下标为1的元素开始放.
    while(i > 0 && i < 11){ 
    String cj = "cj"; 
    if(!cjArray[i].quals("")){ 
    cjList.add(cj + i); 
    log.debug("++++++++++++++++++++++++++++++++++++++++=cj " + (cj + i) ); 

    i++; 

      

  3.   


     List<String> cjList = new ArrayList<String>();
    if(null!=manufacturer1.getText()&&!"".equals(manufacturer1.getText())){

    cjList.add(manufacturer1.getText());
    }


      

  4.   

    manufacturer这个也应该弄成一个数组啊.
      

  5.   


     while(i > 0 && i < 11){
                String cj = "cj";
                if(!(cj + i).equals("")){
                    cjList.add(cj + i);
                    log.debug("++++++++++++++++++++++++++++++++++++++++=cj " + (cj + i) );
                }
                i++;
            }
    能不能在在if的条件里面因为i的不同去取不同的变量?