如何将一些对象数组复制到另一个对象数组
我有这样的课
class sd{
String a="";
String b="";
String c="";
String d="";
int lenph=12;
boolean s=false;
}
和两个这样的数组
sd[] stexp=new sd[12];
sd[] st=new sd[3];
我想将 3 个 stexp 复制到 st 我该怎么做?
我这样做,但它不工作
sd[] stexp=new sd[12];
for(int c=0;c<stexp[0].lenph;c++){
stexp[c]=new sd();
}
sd[] st=new sd[3];
for(int c=0;c<3;c++){
st[c]=new sd();
}
for(int i=0;i<12;i++){
stexp[i].a="f"+i;
stexp[i].b="f"+i;
stexp[i].c="f"+i;
stexp[i].d="f"+i;
}
for(int i=0;i<3;i++){
st[i].a=stexp[i].a;
st[i].b=stexp[i].b;
st[i].c=stexp[i].c;
st[i].d=stexp[i].d;
}
b+=st[0].a+"\n";
b+=st[0].b+"\n";
b+=st[0].c+"\n";
b+=st[0].d+"\n";
sho.setText("b="+b);
谢谢你的帮助。:)
哎呀,我改错了代码。
我想将一个对象数组复制到另一个对象数组,我用
System.arraycopy(stexp, 0,st , 0, 1);
但是当我在eclipse中运行代码时它不起作用。