方法一:
比较直接,就是使用判断,
for(i=0;i<x.getLength-1;i++){字符串+=字符串+‘,’}
if(i==x.getLength()-1){字符串+=字符串}
使用判断语句,到最后一个数时,末尾则不添加符号
方法二:
不使用判断,
StringBuffer str1 = new StringBuffer();
for (String staffId : staffIdsArray) {
if (StringUtils.isEmpty(staffId))
continue;
Staff staff2 = staffService.get(staffId);
System.out.println("mobile=" + staff2.getMobile());
//str1=str1+staff2.getMobile()+"、";
str1.append(staff2.getMobile()).append("、");
}
keywordStr = str1.deleteCharAt(str1.length() - 1).toString();