public boolean addAll(Collection c)
LinkedListlist1 = new LinkedList (); list1.add("apple"); list1.add("banana"); list1.add("orange"); LinkedList list2 = new LinkedList (); list2.add("grape"); list2.add("kiwi"); // add all elements of list2 to the end of list1 list1.addAll(list2); // print the elements of list1 System.out.println(list1);
[apple, banana, orange, grape, kiwi]
LinkedListlist = new LinkedList (); int[] arr = {1, 2, 3, 4, 5}; // add all elements of the array to the end of the list list.addAll(Arrays.asList(arr)); // print the elements of the list System.out.println(list);
[1, 2, 3, 4, 5]The package library for `java.util.LinkedList` is `java.util`.