个List desc=new ArrayList(List c)【参数必须实现Collection接口】 浅拷贝
List des1=new ArrayList(3);
Collections.copy(des1,src1);
只有当desc1的size 大于或者等于src1的size时才进行拷贝,否则抛出IndexOutOfBoundsException异常
所以可以通过下面的方法指定目标desc的大小<br />
/*******************************/
List des1=new ArrayList(Array.asList(new object[src1.size]));//注意:new ArrayList(Collection col)参数必须要实现Collection 接口。</span>
Collections.copy(des1,src1);
/*******************************/
执行第一句后size的大小是3,其实它是对一个空数组的浅拷贝。</span>
替代方法,用apache的CollectionUtils:</p>
dest1
=
new
ArrayList();
CollectionUtils.addAll(dest1, new Object[src1.size()]);
Collections.copy(dest1, src1);
CollectionUtils.addAll(dest1, new Object[src1.size()]);
Collections.copy(dest1, src1);
List<String> tempDecList = new ArrayList<String>(decList.size());
这样写的话tempDecList会初始化decList.size()个null元素,但tempDecList 的size还是0