欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

StringBuilder 实现用“,”拼接手机号码,进行收集短信的批量发送

程序员文章站 2022-06-30 19:53:53
List message = smsMessageGroupService.getSmsMessageGroup(sendMessageParams); //创建map集合 Map map = new HashMap
List<SmsMessageGroupView> message = smsMessageGroupService.getSmsMessageGroup(sendMessageParams);
  //创建map集合
Map<String, Object> map = new HashMap<String, Object>();
//创建StringBuilder
  StringBuilder phone = new StringBuilder();
  //对集合进行遍历,实现拼接
for (int i = 0; i < message.size(); i++) {
try {
if ("".equals(message.get(i).getExigencyPhone())) {

} else {
if (i == message.size() - 1) {
phone.append(message.get(i).getExigencyPhone());
} else {
phone.append(message.get(i).getExigencyPhone());
phone.append(",");
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
}
}

拼接结果是13489098883,13489098883,13489098883,