diff --git a/ArrayList to LinkedList7 b/ArrayList to LinkedList7 new file mode 100644 index 0000000..f528da3 --- /dev/null +++ b/ArrayList to LinkedList7 @@ -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); + } +}