我需要将四个3D数组合并为Java中的单个3D数组,
Object[][][] obj1,obj2,obj3,obj4;
obj1 = new Object[7][8][7];
obj2 = new Object[7][8][7];
obj3 = new Object[7][8][7];
obj4 = new Object[7][8][7];
如上所述,我需要一个
Object[][][] total = Object[28][32][28];
// total = obj1+obj2+obj3+obj4;
答案 0 :(得分:2)
Stream
数组,将流收集到List
,然后转换为数组。像
Object[][][] total = Stream.of(obj1, obj2, obj3, obj4)
.collect(Collectors.toList()).toArray(new Object[0][0][0]);
答案 1 :(得分:0)
我注意到我在流收集之前错过了流的展平。添加“ flatMap”解决了该问题。
data1 = Stream.of(data1, data2).flatMap (a -> Arrays.stream(a)).collect(Collectors.toList()).toArray(new String [0][0]);