IT. Expert System.

Android Reference

PriorityQueue


java.util

Class PriorityQueue<E>

  • All Implemented Interfaces:
    Serializable, Iterable<E>, Collection<E>, Queue<E>


    public class PriorityQueue<E>
    extends AbstractQueue<E>
    implements Serializable
    A PriorityQueue holds elements on a priority heap, which orders the elements according to their natural order or according to the comparator specified at construction time. If the queue uses natural ordering, only elements that are comparable are permitted to be inserted into the queue.

    The least element of the specified ordering is stored at the head of the queue and the greatest element is stored at the tail of the queue.

    A PriorityQueue is not synchronized. If multiple threads will have to access it concurrently, use the PriorityBlockingQueue.

    See Also:
    Serialized Form
    • Constructor Detail

      • PriorityQueue

        public PriorityQueue()
        Constructs a priority queue with an initial capacity of 11 and natural ordering.
      • PriorityQueue

        public PriorityQueue(int initialCapacity)
        Constructs a priority queue with the specified capacity and natural ordering.
        Parameters:
        initialCapacity - the specified capacity.
        Throws:
        IllegalArgumentException - if the initialCapacity is less than 1.
      • PriorityQueue

        public PriorityQueue(int initialCapacity,
                     Comparator<? super E> comparator)
        Constructs a priority queue with the specified capacity and comparator.
        Parameters:
        initialCapacity - the specified capacity.
        comparator - the specified comparator. If it is null, the natural ordering will be used.
        Throws:
        IllegalArgumentException - if the initialCapacity is less than 1.
      • PriorityQueue

        public PriorityQueue(Collection<? extends E> c)
        Constructs a priority queue that contains the elements of a collection. The constructed priority queue has the initial capacity of 110% of the size of the collection. The queue uses natural ordering to order its elements.
        Parameters:
        c - the collection whose elements will be added to the priority queue to be constructed.
        Throws:
        ClassCastException - if any of the elements in the collection are not comparable.
        NullPointerException - if any of the elements in the collection are null.
      • PriorityQueue

        public PriorityQueue(PriorityQueue<? extends E> c)
        Constructs a priority queue that contains the elements of another priority queue. The constructed priority queue has the initial capacity of 110% of the specified one. Both priority queues have the same comparator.
        Parameters:
        c - the priority queue whose elements will be added to the priority queue to be constructed.
      • PriorityQueue

        public PriorityQueue(SortedSet<? extends E> c)
        Constructs a priority queue that contains the elements of a sorted set. The constructed priority queue has the initial capacity of 110% of the size of the sorted set. The priority queue will have the same comparator as the sorted set.
        Parameters:
        c - the sorted set whose elements will be added to the priority queue to be constructed.
    • Method Detail

      • size

        public int size()
        Gets the size of the priority queue. If the size of the queue is greater than the Integer.MAX, then it returns Integer.MAX.
        Specified by:
        size in interface Collection<E>
        Specified by:
        size in class AbstractCollection<E>
        Returns:
        the size of the priority queue.
      • offer

        public boolean offer(E o)
        Inserts the element to the priority queue.
        Specified by:
        offer in interface Queue<E>
        Parameters:
        o - the element to add to the priority queue.
        Returns:
        always true
        Throws:
        ClassCastException - if the element cannot be compared with the elements in the priority queue using the ordering of the priority queue.
        NullPointerException - if o is null.
      • poll

        public E poll()
        Gets and removes the head of the queue.
        Specified by:
        poll in interface Queue<E>
        Returns:
        the head of the queue or null if the queue is empty.
      • peek

        public E peek()
        Gets but does not remove the head of the queue.
        Specified by:
        peek in interface Queue<E>
        Returns:
        the head of the queue or null if the queue is empty.
      • comparator

        public Comparator<? super E> comparator()
        Gets the comparator of the priority queue.
        Returns:
        the comparator of the priority queue or null if the natural ordering is used.
      • remove

        public boolean remove(Object o)
        Removes the specified object from the priority queue.
        Specified by:
        remove in interface Collection<E>
        Overrides:
        remove in class AbstractCollection<E>
        Parameters:
        o - the object to be removed.
        Returns:
        true if the object was in the priority queue, false if the object was not in the priority queue.
      • add

        public boolean add(E o)
        Adds the specified object to the priority queue.
        Specified by:
        add in interface Collection<E>
        Specified by:
        add in interface Queue<E>
        Overrides:
        add in class AbstractQueue<E>
        Parameters:
        o - the object to be added.
        Returns:
        always true.
        Throws:
        ClassCastException - if the element cannot be compared with the elements in the priority queue using the ordering of the priority queue.
        NullPointerException - if o is null.


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 2 / . Delta: 0.04526 с