import java.util.*;
class Maindsa
{
public static void main(String args[])
{
LinkedList<String> list=new LinkedList<>();
//Add the elements to the list
list.add(“apple”); //add elements to the list
list.addFirst(“banana”); //add node to the front
list.addLast(“cherry”); //add node at the end
System.out.println(“Adding elements=” +list);
list.remove();//removes the first element(banana)
System.out.println(“After remove method=” +list);
list.removeFirst();//removes the first element(apple)
System.out.println(“After removefirst method=” +list);
list.removeFirst();//removes the first element(cherry)
System.out.println(“After removefirst method=” +list);
list.add(“grapes”);
list.add(“orange”);
list.add(“mango”);
System.out.println(“updated list=” +list);
//get elements
System.out.println(“Element at the index of 0:” +list.get(0));
System.out.println(“first element:” +list.getFirst());
System.out.println(“last element:” +list.getLast());
//check if the list contains the element or not
System.out.println(“contains ‘apple’?” +list.contains(“apple”));
System.out.println(“contains ‘mango’?” +list.contains(“mango”));
//size of the list
System.out.println(“size of the list=” +list.size());
list.clear();
System.out.println(“After clearing=” +list);}}