
- Java.util Package Classes
- Java.util - Home
- Java.util - ArrayDeque
- Java.util - ArrayList
- Java.util - Arrays
- Java.util - BitSet
- Java.util - Calendar
- Java.util - Collections
- Java.util - Currency
- Java.util - Date
- Java.util - Dictionary
- Java.util - EnumMap
- Java.util - EnumSet
- Java.util - Formatter
- Java.util - GregorianCalendar
- Java.util - HashMap
- Java.util - HashSet
- Java.util - Hashtable
- Java.util - IdentityHashMap
- Java.util - LinkedHashMap
- Java.util - LinkedHashSet
- Java.util - LinkedList
- Java.util - ListResourceBundle
- Java.util - Locale
- Java.util - Observable
- Java.util - PriorityQueue
- Java.util - Properties
- Java.util - PropertyPermission
- Java.util - PropertyResourceBundle
- Java.util - Random
- Java.util - ResourceBundle
- Java.util - ResourceBundle.Control
- Java.util - Scanner
- Java.util - ServiceLoader
- Java.util - SimpleTimeZone
- Java.util - Stack
- Java.util - StringTokenizer
- Java.util - Timer
- Java.util - TimerTask
- Java.util - TimeZone
- Java.util - TreeMap
- Java.util - TreeSet
- Java.util - UUID
- Java.util - Vector
- Java.util - WeakHashMap
- Java.util Package Extras
- Java.util - Interfaces
- Java.util - Exceptions
- Java.util - Enumerations
- Java.util Useful Resources
- Java.util - Useful Resources
- Java.util - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
java.util.PriorityQueue.offer() Method
Description
The offer(E e) method is used to insert the specified element into this priority queue.
Declaration
Following is the declaration for java.util.PriorityQueue.offer() method.
public boolean offer(E e)
Parameters
e − The element to add.
Return Value
The method call returns true (as specified by Queue.offer(E))
Exception
ClassCastException − Throws if the specified element cannot be compared with elements currently in this priority queue according to the priority queue's ordering.
NullPointerException − Throws if the specified element is null.
Example
The following example shows the usage of java.util.PriorityQueue.offer()
package com.tutorialspoint; import java.util.*; public class PriorityQueueDemo { public static void main(String args[]) { // create priority queue PriorityQueue < Integer > prq = new PriorityQueue < Integer > (); // insert values in the queue for ( int i = 0; i < 10; i++ ) { prq.add (new Integer (i)) ; } System.out.println("Initial priority queue values are: "+ prq); // add using offer() function call prq.offer(122); System.out.println("Priority queue values after addition: "+ prq); } }
Let us compile and run the above program, this will produce the following result.
Initial priority queue values are: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Priority queue values after addition: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 122]
java_util_priorityqueue.htm
Advertisements