A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

Create LinkedList having first node item 123 and add more item on this LinkedList. Find the First element of LinkedList.

Programming Steps :

1. Create LinkedList having first node item 123.

       LinkedList  ll = new LinkedList();
       ll.add("deepika");
       ll.addFirst(123);//reserved seat



2. and add more item on this LinkedList. 

       ll.add(2,"Heera");
       ll.add(1,"Tarun");
       ll.addLast("Deepak")



3. Find the First element of LinkedList.

System.out.println("first element is "+ll.getFirst());




Complete Program:


import java.util.LinkedList;
public class A
{
    public static void main(String a[])
    {
       LinkedList  ll = new LinkedList();
       ll.add("deepika");
       ll.addFirst(123);//reserved seat
       ll.add(2,"Heera");
       ll.add(1,"Tarun");
       ll.addLast("Deepak");
      
      
       System.out.println("ll is: "+ll);
       
        System.out.println("first element of ll is "+ll.getFirst());
       
    }
}


LEARN TUTORIALS

.

.