iForeRunner
 
   
 
  JAVA  
   
   
   
 
  Java.util.LinkedList Java Collections -LinkedList implements List interface  
 
 
Java.util.LinkedList -Example--Java Collections
Java Collections -LinkedList ---LinkedList implements LIST Interface

Java.util.LinkedList
Java Collections -LinkedList


LinkedList implements LIST Interface




Example

import java.util.Iterator;
import java.util.LinkedList;

/**
* LinkedList implements interface. Implements all optional list operations,
* and permits all elements (including null). In addition to implementing the List interface,
* provides uniformly named methods to get, remove and insert an element ( addFirst, addLast)
* at the beginning and end of the list.
* linkedlists would be used as a stack, queue, or double-ended queue (deque).
* Above is extract from www.SUN.com
* CHAITANYA KANDIKONDA
* @author Darur
*
*/
public class LinkedListDemo {
public LinkedList addValuestoLinkedList( ){
LinkedList linkedList = new LinkedList();
linkedList.add( 1 );
linkedList.add( 2 );
linkedList.add( 7 );
linkedList.add( 7 );
linkedList.add( 8 );
linkedList.add( 3 );
linkedList.add( 4 );
linkedList.add( 5 );
linkedList.add( 6 );
linkedList.add( 7 );
return linkedList;
}
// add first element
// add last element and print
public void PrintLinkedList( LinkedList linkedList ){
linkedList.addFirst( 0 );
linkedList.addLast( 10 );
Iterator iterator = linkedList.iterator();
while( iterator.hasNext() ){
System.out.println( "THE VALUE: " + iterator.next());
}
}

public static void main( String [] args ){
LinkedListDemo linkedListDemo = new LinkedListDemo();
LinkedList linkedList =linkedListDemo.addValuestoLinkedList();
linkedListDemo.PrintLinkedList(linkedList);
}

}






Output :


THE VALUE: 0
THE VALUE: 1
THE VALUE: 2
THE VALUE: 7
THE VALUE: 7
THE VALUE: 8
THE VALUE: 3
THE VALUE: 4
THE VALUE: 5
THE VALUE: 6
THE VALUE: 7
THE VALUE: 10

Please send comments to vgdarur.javafive@blogger.com

 
     
 
 
 
http://www.iforerunner.com/