I have 35 categories inside this list List<CategoriesModel> categoriesModelList;
, and I want to clone all names and put them inside this array String[] namesList
, I'm currently cloning names using this code but I want to ask is there any method can clone names from list to the specific array without creating a loop?
String[] namesList = new String[categoriesModelList.size()];
for (int i = 0; i < categoriesModelList.size(); i++)
namesList[i] = categoriesModelList.get(i).getName();
CategoriesModel.java
public class CategoriesModel {
private int id;
private String name;
private boolean supportSubcategories;
public CategoriesModel(int id, String name, boolean supportSubcategories) {
this.id = id;
this.name = name;
this.supportSubcategories = supportSubcategories;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public boolean isSupportSubcategories() {
return supportSubcategories;
}
}