The code demonstrates how to join an ArrayList to the end of a LinkedList in Java. The JoinArrayList_EndLinkedlist class contains a main method where a LinkedList of strings, link_list, is created and populated with some values using the add method. The link_list contains the strings "Blue", "Green", "Pink", "Black", "Red", and "Orange".
An ArrayList of strings, array_list, is also created and populated with some values using the add method. The array_list contains the strings "Yellow", "White", "Purple", and "Gray".
The addAll method is called on the link_list linked list, passing in the array_list as an argument, to append the elements of the array_list to the end of the link_list.
Finally, the resulting linked list with the appended elements from the array list is printed using System.out.println.
import java.util.*; public class JoinArrayList_EndLinkedlist { public static void main(String[] args) { LinkedList<String> link_list = new LinkedList<String>(); link_list.add("Blue"); link_list.add("Green"); link_list.add("Pink"); link_list.add("Black"); link_list.add("Red"); link_list.add("orange"); System.out.println("Element of LinkedList : "+link_list); ArrayList<String> array_list = new ArrayList<String>(); array_list.add("Yellow"); array_list.add("White"); array_list.add("Purple"); array_list.add("Gray"); System.out.println("Element of ArrayList : "+array_list); link_list.addAll(array_list); System.out.println("Appending arrayList at the end of linkedList.."); System.out.println(link_list); } }
Element of LinkedList : [Blue, Green, Pink, Black, Red, orange] Element of ArrayList : [Yellow, White, Purple, Gray] Appending arrayList at the end of linkedList.. [Blue, Green, Pink, Black, Red, orange, Yellow, White, Purple, Gray]
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions