您的位置:首页 > 其它

String[] 数组判断值不能重复

2017-08-14 14:50 183 查看
String[] price = getParaValues("price");

//用于判断规格是否有重复值的标记
boolean flag=false;
for (int i = 0; i < spec_name.length; i++) {
 String temp=spec_name[i];
 int count=0;
 for (int j = 0; j < spec_name.length; j++) {
 String temp2=spec_name[j];
  //有重复值就count+1 
  if(temp.equals(temp2)){
   count++;
  }
 }
 //由于中间又一次会跟自己本身比较所以这里要判断count>=2
 if(count>=2){
  flag=true;
 }
}
if(flag){
       
renderFail("规格不可以重复");
       
}else{
       
service.update(commodity, spec_name, price);
    this.renderJson(200, " 修改成功!");
       
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: