LinkedList

LinkedList

  • The underlying data structure for LinkedList is double LinkedList.
  • Insertion order is preserve.
  • Duplicate objects are allowed.
  • Heterogeneous objects are allowed.
  • Null insertion is possible.
  • Implements Serializable & Cloneable interface but not Random Access.
  • LinkedList is not suitable if our frequent operation is not retrieval operation.

Constructors:-

  • LinkedList l = new LinkedList ();

creates an empty LinkedList objects.

  • LinkedList l = new LinkedList ( collection c )

In general, LinkedList an be used for implementing Stacks and Queue. To support this requirement LinkedList class define the following specific method.

  1. void add First ( object o )
  2. void add Last ( object o )
  3. void  remove First ( )
  4. void  remove Last( )
  5. void  get First ( ) ;
  6. void get Last ( );
import java. until. * ;
Class Exam LinkedList
{
 public static void main(string[] args)  
       {
          LinkedList l = new LinkedList ();
          l. add ( "narayana" );
          l. add (30);
          l. add (null);
          l. set ( o, "s/w" ) ;
          l. add ( o, anitha" );
          l. remove Last ();
          l. add First ( "ccc" );
          System.out.println (l);
      }
}

Leave a Reply