Java ArrayList.addAll(int index, Collection c)

转自:http://www.java2s.com/Tutorials/Java/java.util/ArrayList/Java_ArrayList_addAll_int_index_Collection_lt_extends_E_gt_c_.htm 

import java.util.ArrayList;

public class Main {
  public static void main(String args[]) {
    ArrayList<Integer>  arrlist = new ArrayList<Integer> (5);
  
    arrlist.add(1);
    arrlist.add(2);
    arrlist.add(4);

    System.out.println(arrlist);

    ArrayList<Integer>  arrlist2 = new ArrayList<Integer> (5);
  
    arrlist2.add(25);
    arrlist2.add(30);
    arrlist2.add(31);
    arrlist2.add(35);

    System.out.println(arrlist2);

    // inserting all elements of list2 at third position
    arrlist.addAll(2, arrlist2);
  
    System.out.println(arrlist);
    
    
  }
}

The code above generates the following result.

 

你可能感兴趣的:(笔记)