-
Notifications
You must be signed in to change notification settings - Fork 0
/
Collections1.java
56 lines (47 loc) · 1.67 KB
/
Collections1.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.util.*;
class Collections1
{
public static void main(String arg[])
{
LinkedList <Integer>lobj = new LinkedList<Integer>();
lobj.add(11);
lobj.add(21);
lobj.add(51);
lobj.add(101);
lobj.add(111);
System.out.println("Elements of Linked list are :"+lobj);
lobj.addFirst(1);
System.out.println("Elements of Linked list are :"+lobj);
lobj.addLast(121);
System.out.println("Elements of Linked list are :"+lobj);
Iterator iobj = lobj.iterator();
System.out.println("Data using iterator is :");
while(iobj.hasNext())
{
System.out.println(iobj.next());
}
if(lobj.contains(121))
{
System.out.println("121 is present in the linkedlist");
}
else
{
System.out.println("121 is not present in the linked list");
}
lobj.remove();
System.out.println("Elements of Linked list are :"+lobj);
lobj.remove();
System.out.println("Elements of Linked list are :"+lobj);
lobj.remove(1);
System.out.println("Elements of Linked list are :"+lobj);
lobj.remove(0);
System.out.println("Elements of Linked list are :"+lobj);
lobj.removeLast();
System.out.println("Elements of Linked list are :"+lobj);
System.out.println("Elements of Linked list are :"+lobj.size());
lobj.set(1, 500);
System.out.println("Elements of Linked list are :"+lobj);
lobj.clear();
System.out.println("Elements of Linked list are :"+lobj);
}
}