下面的 ismy 代码在最后一个循环中工作正常唯一的问题我想改变一点我怎么知道是最后一个循环?我的代码在 forloop 结束时不满足这个条件 if(i == school5.length()-1) 而不是用 . 我会做什么请帮帮我
JSONArray school5 = json2.getJSONArray("dish_ingredient");
String concatProduct = "";
for (int i = 0; i < school5.length(); i++) {
String name = school5.getJSONObject(i).getString("name");
String subIngredient = school5.getJSONObject(i).getString("sub_ingredients");
if(i == 0){
if (subIngredient.equals(""))
{
if(i == school5.length()-1)
{
concatProduct = " " + "<b>" + name + "</b>"+". " + subIngredient;
}
else
{
concatProduct = " " + "<b>" + name + "</b>"+", " + subIngredient;
}
}
else
{
concatProduct = " " + "<b>" + name + "</b>"+": " + subIngredient;
}
} else {
if (subIngredient.equals(""))
{
concatProduct += " " + "<b>" + name + "</b>"+", " + subIngredient;
}
else
{
concatProduct += " " + "<b>" + name + "</b>"+": " + subIngredient;
}
}
}