-
Notifications
You must be signed in to change notification settings - Fork 71
/
LinkedList.java
33 lines (31 loc) · 1.24 KB
/
LinkedList.java
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
import java.util.*;
public class LinkedList{
public static void main(String args[]){
LinkedList<String> ll=new LinkedList<String>();
System.out.println("list of the elements: "+ll);
ll.add("Paba");
ll.add("Sarani");
ll.add("Aqee");
System.out.println("Then: "+ll);
//Adding an element at the specific position
ll.add(1, "Maya");
System.out.println("Then: "+ll);
LinkedList<String> ll2=new LinkedList<String>();
ll2.add("chala");
ll2.add("kavi");
ll.addAll(ll2);
System.out.println("Then: "+ll);
LinkedList<String> ll3=new LinkedList<String>();
ll3.add("Gayan");
ll3.add("Gamage");
//Adding second list elements to the first list at specific position
ll.addAll(1, ll3);
System.out.println("Then: "+ll);
//Adding an element at the first position
ll.addFirst("Lashesh");
System.out.println("Then: "+ll);
//Adding an element at the last position
ll.addLast("Harish");
System.out.println("Then: "+ll);
}
}