Wu Yuxiong - born naturally develop common java class library study notes: LinkedList class

import java.util.LinkedList ;
public class LinkedListDemo01{
    public static void main(String args[]){
        LinkedList<String> link = new LinkedList<String>() ;
        link.add ( "A");     // add elements 
        link.add ( "B");     // add elements 
        link.add ( "C");     // add elements 
        System.out.println ( "initialization list:" + Link);
        link.addFirst ( "X-");     // increase the data at the beginning 
        link.addLast ( "the Y");         // increase the data at the end 
        System.out.println ( "increase after the head and tail list:" + Link);
    }
};
import java.util.LinkedList ;
public class LinkedListDemo02{
    public static void main(String args[]){
        LinkedList<String> link = new LinkedList<String>() ;
        link.add ( "A");     // add elements 
        link.add ( "B");     // add elements 
        link.add ( "C");     // add elements 
        System.out.println ( "1-1, element () method finds the header: "+ link.element ());
        System.out.println ( "1-2, after the contents of the list to find End:" + Link);
        System.out.println ( "2-1, PEEK () method finds the header:" + link.peek ());
        System.out.println ( "2-2, after the contents of the list to find End:" + Link);
        System.out.println ( "3-1, poll () method finds the header:" + link.poll ());
        System.out.println ( "3-2, after the contents of the list to find End:" + Link);
        
    }
};
import java.util.LinkedList ;
public class LinkedListDemo03{
    public static void main(String args[]){
        LinkedList<String> link = new LinkedList<String>() ;
        link.add ( "A");     // add elements 
        link.add ( "B");     // add elements 
        link.add ( "C");     // add elements 
        System.out.print ( "FIFO manner in output: " );
         for ( int I = 0; I <= link.size () +. 1; I ++ ) {
            System.out.print(link.poll() + "、") ;
        }
    }
};

 

Guess you like

Origin www.cnblogs.com/tszr/p/12152690.html