我有一个像这样的数据类,可以从API获取数据。
data class Ingredient(
val idMeal: String?,
val strArea: String?,
val strCategory: String?,
val strIngredient1: String?,
val strIngredient2: String?,
.
.
.
val strMealThumb: String?,
val strMeasure1: String?,
val strMeasure2: String?,
.
.
.
)
是否有一种优雅的方法可以将strIngredient ##和strMeasure ##放入循环列表中,而不是手动进行处理?
if(ingredient.strIngredient1!="") ingredientsList.add("•"+ingredient.strIngredient1 +" : "+ ingredient.strMeasure1)
if(ingredient.strIngredient2!="") ingredientsList.add("•"+ingredient.strIngredient2 +" : "+ ingredient.strMeasure2)
.
.