ArrayList addAll (int fromIndex, Collection c) example

 ArrayList addAll (int fromIndex, Collection c) example



ArrayList<String> list1 = new ArrayList<>();    //list 1
         
        list1.add("A");
        list1.add("B");
        list1.add("C");
        list1.add("D");
         
        ArrayList<String> list2 = new ArrayList<>();    //list 2
         
        list2.add("E");
        list2.add("F");
         
        list1.addAll(2, list2); //Elements will be inserted from index 2
         
        System.out.println(list1);      //combined list

Output: [A, B, E, F, C, D]
ArrayList addAll (int fromIndex, Collection c) example ArrayList addAll (int fromIndex, Collection c) example Reviewed by TechTubeHQ on July 02, 2022 Rating: 5

No comments:

Powered by Blogger.