-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlinked_list.java
37 lines (30 loc) · 1.31 KB
/
linked_list.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
import java.util.*;
public class linked_list
{
public static void main(String[] args)
{
LinkedList<String> object =new LinkedList<String>();//creating a obj of class linked list
object.add("A");//adding elements in linked list
object.add("B");
object.addLast("C");
object.addFirst("D");
object.add("F");
object.add("G");
object.add(2,"E");//adding element at second possition
System.out.println("linked list : " + object);
object.remove("B");//removing element
object.remove(3);//removing third element
object.removeFirst();//removing the first element
object.removeLast();//removing the last element
System.out.println("linked list after deletion : " + object);
boolean status = object.contains("E");//checking the element in the list
if(status)
System.out.println("list contain the element 'E' ");
else
System.out.println("list dont contain the element 'E' ");
int size = object.size();//getting the size of the list
System.out.println("size of the list is :" + size);
object.set(2, "Y");//changing the element
System.out.println("linked list after change" + object);
}
}