Cloning.JAVA源码

没下载到源码,自己写了一份




import java.util.ArrayList;
import java.util.Iterator;


class Int {
private int i;


public Int(int ii) {
i++;
}


public void increment() {
i++;
}


public String toString() {
return Integer.toString(i);
}
}


/**
 * @Cloning
 * @hp
 * @下午11:15:02 @ author:fanjf @
 */
public class Cloning {


/**
* 函数功能说明: 创建者: fanjf 修改者: fanjf 修改日期: 2013-12-14 修改内容

* @参数:
* @return void
* @throws
*/


public static void main(String[] args) {
ArrayList v = new ArrayList();
for (int i = 0; i < 10; i++) {
v.add(new Int(i));
System.out.println("v===" + i + "-" + v);
ArrayList v2 = (ArrayList) v.clone();
for (Iterator e = v2.iterator(); e.hasNext();) {
((Int) e.next()).increment();
System.out.println("v: " + v);
}/**/
}


}


}


运行效果:



v===0-[1]
v: [2]
v===1-[2, 1]
v: [3, 1]
v: [3, 2]
v===2-[3, 2, 1]
v: [4, 2, 1]
v: [4, 3, 1]
v: [4, 3, 2]
v===3-[4, 3, 2, 1]
v: [5, 3, 2, 1]
v: [5, 4, 2, 1]
v: [5, 4, 3, 1]
v: [5, 4, 3, 2]
v===4-[5, 4, 3, 2, 1]
v: [6, 4, 3, 2, 1]
v: [6, 5, 3, 2, 1]
v: [6, 5, 4, 2, 1]
v: [6, 5, 4, 3, 1]
v: [6, 5, 4, 3, 2]
v===5-[6, 5, 4, 3, 2, 1]
v: [7, 5, 4, 3, 2, 1]
v: [7, 6, 4, 3, 2, 1]
v: [7, 6, 5, 3, 2, 1]
v: [7, 6, 5, 4, 2, 1]
v: [7, 6, 5, 4, 3, 1]
v: [7, 6, 5, 4, 3, 2]
v===6-[7, 6, 5, 4, 3, 2, 1]
v: [8, 6, 5, 4, 3, 2, 1]
v: [8, 7, 5, 4, 3, 2, 1]
v: [8, 7, 6, 4, 3, 2, 1]
v: [8, 7, 6, 5, 3, 2, 1]
v: [8, 7, 6, 5, 4, 2, 1]
v: [8, 7, 6, 5, 4, 3, 1]
v: [8, 7, 6, 5, 4, 3, 2]
v===7-[8, 7, 6, 5, 4, 3, 2, 1]
v: [9, 7, 6, 5, 4, 3, 2, 1]
v: [9, 8, 6, 5, 4, 3, 2, 1]
v: [9, 8, 7, 5, 4, 3, 2, 1]
v: [9, 8, 7, 6, 4, 3, 2, 1]
v: [9, 8, 7, 6, 5, 3, 2, 1]
v: [9, 8, 7, 6, 5, 4, 2, 1]
v: [9, 8, 7, 6, 5, 4, 3, 1]
v: [9, 8, 7, 6, 5, 4, 3, 2]
v===8-[9, 8, 7, 6, 5, 4, 3, 2, 1]
v: [10, 8, 7, 6, 5, 4, 3, 2, 1]
v: [10, 9, 7, 6, 5, 4, 3, 2, 1]
v: [10, 9, 8, 6, 5, 4, 3, 2, 1]
v: [10, 9, 8, 7, 5, 4, 3, 2, 1]
v: [10, 9, 8, 7, 6, 4, 3, 2, 1]
v: [10, 9, 8, 7, 6, 5, 3, 2, 1]
v: [10, 9, 8, 7, 6, 5, 4, 2, 1]
v: [10, 9, 8, 7, 6, 5, 4, 3, 1]
v: [10, 9, 8, 7, 6, 5, 4, 3, 2]
v===9-[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
v: [11, 9, 8, 7, 6, 5, 4, 3, 2, 1]
v: [11, 10, 8, 7, 6, 5, 4, 3, 2, 1]
v: [11, 10, 9, 7, 6, 5, 4, 3, 2, 1]
v: [11, 10, 9, 8, 6, 5, 4, 3, 2, 1]
v: [11, 10, 9, 8, 7, 5, 4, 3, 2, 1]
v: [11, 10, 9, 8, 7, 6, 4, 3, 2, 1]
v: [11, 10, 9, 8, 7, 6, 5, 3, 2, 1]
v: [11, 10, 9, 8, 7, 6, 5, 4, 2, 1]
v: [11, 10, 9, 8, 7, 6, 5, 4, 3, 1]
v: [11, 10, 9, 8, 7, 6, 5, 4, 3, 2]



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值