我想在最后一次迭代中跳过打印“,”。
我想要输出像名字,名字,名字
现在我得到的输出是名称,名称,名称,
StringBuffer stringBuffer = new StringBuffer();
for(MovieModel.Cast cast : movieModelList.get(position).getCastList()){
stringBuffer.append(cast.getName() + ", ");
}
最佳答案
您可以在附加名称之前附加逗号。像这样:
StringBuffer stringBuffer = new StringBuffer();
for(MovieModel.Cast cast : movieModelList.get(position).getCastList()){
if (stringBuffer.length() != 0) {
stringBuffer.append(",");
}
stringBuffer.append(cast.getName());
}
关于java - 在每个循环中,我想在最后一次迭代中跳过 ", ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44087405/