-
Notifications
You must be signed in to change notification settings - Fork 0
/
Collections2.java
56 lines (47 loc) · 1.72 KB
/
Collections2.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 Collections2
{
public static void main(String arg[])
{
LinkedList <String>lobj = new LinkedList<String>();
lobj.add("Kapil");
lobj.add("Aditya");
lobj.add("Rohan");
lobj.add("Rutik");
lobj.add("Tejas");
System.out.println("Elements of Linked list are :"+lobj);
lobj.addFirst("Pooja");
System.out.println("Elements of Linked list are :"+lobj);
lobj.addLast("Sneha");
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("Rohan"))
{
System.out.println("Rohan is present in the linkedlist");
}
else
{
System.out.println("Rohan 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, "Deepak");
System.out.println("Elements of Linked list are :"+lobj);
lobj.clear();
System.out.println("Elements of Linked list are :"+lobj);
}
}