Java Other collections

一, and recount

public  class DequeDemo {
     / * 
     * the Deque <E> implements a deque, may be added to the tail may also be added to the head of the queue, either the first acquisition may also be obtained from the tail from the team 
     * extended to Queue Interface 
     * Total a method using first and the last with 
     * add null to avoid queue 
     * / 

    public  static  void main (String [] args) { 
        the Deque <String> = the deque new new the LinkedList <> (); 
        deque.offerFirst ( "Yuan" ) ; 
        deque.offerLast ( "Qi" ); 
        deque.offerFirst ( "DAI" ); 
        
        System.out.println (the deque); 
        System.out.println (deque.pollFirst ());  
        System.out.println (the deque.pollLast());
        System.out.println (the deque);

    }

}

 

Two, Queue

public  class QueueTest { 
    
    / * 
     * Queue <E> implements a FIFO queue 
     * the LinkedList implements Queue <E> Interface 
     * conventional method 
     * add / offer additional element 
     * remove / poll acquisition queue and delete the header element, after If the elements are null, null is returned to the same below 
     * element / peek acquired without deleting the header element 
     * / 

    public  static  void main (String [] args) {
         // the TODO Auto-Generated Method Stub 
        Queue <Teacher> Q = new new PriorityQueue <> (); // can also add an annotation comparactor objects, PriorityQueue <> (new new comparactor <Teacher> ()) 
        
        q.add ( new new Teacher ( "Jack", 23 is )); 
        q.add ( new new Teacher("mary", 33));
        q.add(new Teacher("calve", 21));
        
        //按名字排序输出
        System.out.println(q.poll());
        System.out.println(q.poll());
        System.out.println(q.poll());
    }

    private static void m1() {
        Queue q = new LinkedList();
        Queue<Student> qu = new PriorityQueue<>();
        
        q.offer(12);
        q.offer(true);
        q.offer("yuan");
        q.offer(new Student("jack", 23));
    
        System.out.println(q.poll());
        System.out.println(q.poll());
        System.out.println(q.poll());
        System.out.println(q.poll());
        System.out.println(q.poll());//null
        //System.out.println(q.remove());//java.util.NoSuchElementException
    }

}

 

Guess you like

Origin www.cnblogs.com/noperx/p/11372537.html