I like to combine two common arrays in pairs on BiFunction . Here you see a naive implementation:
<A,B,C> C[] combine(A[] as, B[] bs, BiFunction<A,B,C> op) { if (as.length == bs.length) { C[] cs = (C[]) new Object[as.length]; for(int i = 0; i < as.length; i++) { cs[i] = op.apply(as[i], bs[i]); } return cs; } else { throw new IllegalArgumentException(); } }
I wonder if there is a more elegant way to do this without a for loop - perhaps with Java 8 Stream . I would appreciate your suggestions.
source share