-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLinkedListpgm.java
More file actions
65 lines (56 loc) · 1.84 KB
/
Copy pathLinkedListpgm.java
File metadata and controls
65 lines (56 loc) · 1.84 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package JavaPgm;
import static org.testng.Assert.assertEqualsNoOrder;
import java.util.Iterator;
import java.util.LinkedList;
public class LinkedListpgm {
public static void main(String[] args)
{
LinkedList ll=new LinkedList();
ll.add("anand");
ll.add(13);
ll.add('a');
for(int i=0;i<ll.size();i++)
{
System.out.println(ll.get(i));
}
LinkedList<String> lls=new LinkedList<String>();
lls.add("anand");
lls.add("mohan");
lls.add("Patel");
System.out.println("######Generic########");
System.out.println("content of linked Text"+lls);
for(int i=0;i<lls.size();i++)
{
System.out.println(lls.get(i));
}
System.out.println("######ForEach########");
for (String s:lls)
{
System.out.println(s);
}
System.out.println("######Iterator########");
Iterator<String> it=lls.iterator();
while(it.hasNext())
{
System.out.println(it.next());
}
lls.addFirst("Automation");
System.out.println("######addFirst########");
System.out.println("content of linked Text"+lls);
lls.addLast("Engineer");
System.out.println("######AddLast########");
System.out.println("content of linked Text"+lls);
lls.set(0, "java");
System.out.println("######set at index########");
System.out.println("content of linked Text"+lls);
lls.removeLast();
System.out.println("######removelast########");
System.out.println("content of linked Text"+lls);
lls.removeFirst();
System.out.println("######removeFirst########");
System.out.println("content of linked Text"+lls);
lls.remove(2);
System.out.println("######removing 2nd Element########");
System.out.println("content of linked Text"+lls);
}
}