From 41a34ba2d54bc745fb08940848056d6195599818 Mon Sep 17 00:00:00 2001 From: deepikagupta091999 <116456998+deepikagupta091999@users.noreply.github.com> Date: Sat, 22 Oct 2022 23:33:32 +0530 Subject: [PATCH] Create ArrayList to LinkedList6 --- ArrayList to LinkedList6 | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 ArrayList to LinkedList6 diff --git a/ArrayList to LinkedList6 b/ArrayList to LinkedList6 new file mode 100644 index 0000000..f528da3 --- /dev/null +++ b/ArrayList to LinkedList6 @@ -0,0 +1,45 @@ +// Java Program to convert +// ArrayList to LinkedList +// using Naive method + +import java.util.*; +import java.util.stream.*; + +class GFG { + + // Generic function to convert an ArrayList to LinkedList + public static List convertALtoLL(List aL) + { + + // Create an empty LinkedList + List lL = new LinkedList<>(); + + // Iterate through the aL + for (T t : aL) { + + // Add each element into the lL + lL.add(t); + } + + // Return the converted LinkedList + return lL; + } + + public static void main(String args[]) + { + // Create an ArrayList + List aL = Arrays.asList("Geeks", + "forGeeks", + "A computer Portal"); + + // Print the ArrayList + System.out.println("ArrayList: " + aL); + + // convert the ArrayList to LinkedList + List + lL = convertALtoLL(aL); + + // Print the LinkedList + System.out.println("LinkedList: " + lL); + } +}