forked from dharmanshu1921/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayList to LinkedList3
More file actions
46 lines (35 loc) · 893 Bytes
/
ArrayList to LinkedList3
File metadata and controls
46 lines (35 loc) · 893 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// 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 <T> List<T> convertALtoLL(List<T> aL)
{
// Create an empty LinkedList
List<T> 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<String> aL = Arrays.asList("Geeks",
"forGeeks",
"A computer Portal");
// Print the ArrayList
System.out.println("ArrayList: " + aL);
// convert the ArrayList to LinkedList
List<String>
lL = convertALtoLL(aL);
// Print the LinkedList
System.out.println("LinkedList: " + lL);
}
}
ArrayList to LinkedList3