I have an array with Type B[]
. I have a constructor A(B b)
.
I want to create an array with Type A[]
using them.
I can use the for statement to do that, but I want to know whether there is a more convinient(shorter) way to do this. (Language syntax, static method, or whatever)
public class A {
public A(B b) {
A.a = B.a;
A.b = B.b * B.c;
...
}
}
public class B {
...
}
public class C {
public static B[] getBs() {
B[] bs;
...
return bs;
}
}
void process() {
// From here
B[] bs = C.getBs();
A[] as = new A[bs.length];
for (int i=0; i<bs.length; i++) {
as[i] = new A(bs[i]);
}
// To here
}