我一直在尝试找到我的问题的解决方案,我有一个调用的数组,我想将其划分为数组(foodsArray),因此每个数组包含3个对象。例如:FoodsfoodsFood[[Food1, Food2, Food3], [Food4, Food5, Food6]]
我目前已经实现了我的问题,就像这样:
Food[] foods = new Food[foodData.length]; //loaded in from a file
List<Food> foodsArray = new ArrayList<Food>();
for(int i=0;i<foods.length;i+=5){
foodsArray.add(Arrays.copyOfRange(foods, i, Math.min(foods,i+5))); //error is here
//Output
System.out.println(Arrays.toString(Arrays.copyOfRange(foods, i, Math.min(foods,i+5))));
}
当前结果(食物阵列):[[Lcom.company.Food;@3c756e4d, [Lcom.company.Food;@7c0e2abd, [Lcom.company.Food;@48eff760, [Lcom.company.Food;@402f32ff]
预期结果(食物阵列):
[[com.company.Food@458ad742, com.company.Food@48eff760, com.company.Food@402f32ff],
[com.company.Food@6d8a00e3, com.company.Food@548b7f67, com.company.Food@7ac7a4e4],
[com.company.Food@5dfcfece]]
拉风的咖菲猫
素胚勾勒不出你
相关分类