浅拷贝
1、遍历循环复制
List<Person> destList = new ArrayList<Person>(srcList.size());
for(Person p : srcList){
destList.add(p);
}
2、使用List实现类的构造方法
List<Person> destList = new ArrayList<Person>(srcList);
3、使用list.addAll()方法
List<Person> destList = new ArrayList<Person>();
destList.addAll(srcList);
4、使用System.arraycopy()方法
Person[] srcPersons = srcList.toArray(new Person[0]);
Person[] destPersons = new Person[srcPersons.length];
System.arraycopy(srcPersons, 0, destPersons, 0, srcPersons.length);
深拷贝
1.Collections.copy()方法
final List<BottomBarAppBean> gridItems = mSglApps.getGridItems();
final ArrayList<BottomBarAppBean> destItems = new ArrayList<>();
Collections.addAll(destItems, new BottomBarAppBean[gridItems.size()]);
Collections.copy(destItems, gridItems);
参考博客:
https://blog.youkuaiyun.com/never_tears/article/details/79067245
254

被折叠的 条评论
为什么被折叠?



