Below programs illustrate poll () method of ArrayBlockingQueue. Syntax: public E poll () Return Value: The method returns the element from the head of this queue, or null if this queue is empty. If queue is empty then method will return null. So if you insert null and get null from poll() you can't say is it your inserted one or the LinkedList is empty. The poll () method retrieves and removes element from head of this queue. The head of this list, or null if this list is empty Syntax public E poll() Parameter This method does not accept any parameters. The PriorityQueue.poll () method is used to remove the element present at the head of the PriorityQueue. So you can insert null in LinkedList but you shouldn't specially if you use LinkedList as a queueīecause poll() method of LinkedList Returns: The PriorityQueue.poll () method is present in the PriorityQueue class inside the java.util package. Even in the implementations that permit it, null should not be inserted into a Queue, as null is also used as a special return value by the poll method to indicate that the queue contains no elements. not restricted ) LinkedList linkdeList=new LinkedList() LinkedList also implements Queue but it allow null value. Although some implementations, such as LinkedList, do not prohibit insertion of null. The methods that add elements to the Queue will then wake up waiting threads when an element is added, so minimal time is spent checking the queue over.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |