java lined up use cases

  1.   java linear queue is a special table, only delete operation is allowed at the front end of the table, while the rear end of the insertion operation table.
  2.   FIFO has properties

         

         LinkedList class implements the Queue interface, so that we can put to use LinkedList as a Queue:

        

       // the Add () and remove () method at the time of failure will throw an exception (not recommended) 
       Queue <String> = Queue new new LinkedList <String> ();
        // add elements 
       Queue.offer ( "A" );
       queue.offer("b");
       queue.offer("c");
       queue.offer("d");
       queue.offer("e");
       for(String q : queue){
           System.out.println(q);
       }

 

       System.out.println ( "poll =" + queue.poll ()); // return the first element in the queue and delete 
        for (String Q: Queue) {
            System.out.println(q);
        }
        System.out.println ( "Element =" + queue.element ()); // returns the first element is not deleted 
        for (String Q: Queue) {
            System.out.println(q);
        }
        System.out.println ( "PEEK =" + queue.peek ()); // returns the first element is not deleted 
        for (String Q: Queue) {
            System.out.println(q);
        }

 

Guess you like

Origin www.cnblogs.com/qq376324789/p/11386987.html