java中
ArrayList list1 = new ArrayList();
list1.add...
ArrayList list2 = new ArrayList();
list2.add...
ArrayList list3 = new ArrayList();
list3.add...
java中,有三个ArrayList 变量,并都赋了值,
现问,如何把这三个ArrayList 变量 拼成一个ArrayList呢,
随机拼起来,可以 list1 list2list3 也可以 231 等
thanks
------解决方案--------------------
addAll
------解决方案--------------------
list1.addAll(list2);
list1.addAll(list3);
------解决方案--------------------
- Java code
public ArrayList addAllArrayList(ArrayList... list) { if (list == null || list.length < 1) { return null; } int size = 0; ArrayList finalList = new ArrayList(); for (ArrayList one : list) { finalList.addAll(size, one); size += one.size(); } return finalList; }