我试图将一个数组的内容复制到另一个数组而不指向相同的内存,但我不能。
我的代码:
class cPrueba {
    private float fvalor;
    public float getFvalor() {
        return fvalor;
    }
    public void setFvalor(float fvalor) {
        this.fvalor = fvalor;
    }
}
List<cPrueba> tListaPrueba = new ArrayList<cPrueba>();
List<cPrueba> tListaPrueba2 = new ArrayList<cPrueba>();
cPrueba tPrueba = new cPrueba();
tPrueba.setFvalor(50);
tListaPrueba.add(tPrueba);
tListaPrueba2.addAll(tListaPrueba);
tListaPrueba2.get(0).setFvalor(100);
System.out.println(tListaPrueba.get(0).getFvalor());
结果是“100.0” ....
仍然指向同一个对象......任何简单的复制方法?(没有 for(..){})
编辑:
class cPrueba implements Cloneable {
    private float fvalor;
    public float getFvalor() {
        return fvalor;
    }
    public void setFvalor(float fvalor) {
        this.fvalor = fvalor;
    }
    public cPrueba clone() {
        return this.clone();
    }
}
List<cPrueba> tListaPrueba = new ArrayList<cPrueba>();
List<cPrueba> tListaPrueba2 = new ArrayList<cPrueba>();
cPrueba tPrueba = new cPrueba();
tPrueba.setFvalor(50);
tListaPrueba.add(tPrueba);
for ( cPrueba cp : tListaPrueba )
    tListaPrueba2.add(cp);
tListaPrueba2.get(0).setFvalor(100);
System.out.println(tListaPrueba.get(0).getFvalor());
还是要100...