xuhk1819

遍历分割后的数组

//去掉所有空格,以逗号截取字符串成数组
List<String> phoneNoList=new ArrayList<String>();
String[] phoneNos = phonesGroupVO.getPhoneNos().replace(" ", "").split(",");
//以多个符号来截取字符串,比如分号和逗号:
String[] phoneNos = phonesGroupVO.getPhoneNos().replace(" ", "").split(",|;");
//或
String[] phoneNos = phonesGroupVO.getPhoneNos().replace(" ", "").split("[,;]");
//1.用增强的for循环遍历
for(String str:phoneNos){
    if(!phoneNoList.contains(str)){
        phoneNoList.add(str);
    }
}
//2.用for循环遍历
for(int i=0;i<phoneNos.length;i++){ 
  if(!phoneNoList.contains(phoneNos[i])){
    phoneNoList.add(phoneNos[i]);
  }
}

另:分割字符串的时候,如果遇到按英文句号(即.)来分割的,那需要加双斜杠来转义,例如:
String[] fileNamea = oriFileName.split("\\.");
 
 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-20
  • 2021-09-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案