![]() However in case of any confusion you can always come back here to consult. ConclusionBy the end, we hope you’re familiar with the use and working of poll() method of Queues. Moreover, is thrown when we call remove() at an empty queue, while no such exception is thrown for using poll(). E remove(): This method removes the head(first element) of the Queue and returns its value. ![]() And as we use remove() or poll() the size of the queue is reduced by 1 alongwith returning the head. boolean offer(object): This is same as add() method. ("remove() returned: " + days.remove()) Įxception in thread "main" Īt (LinkedList.java:270)Īt (LinkedList.java:685)Īt QueuePollMethod.main(QueuePollMethod.java:48)Īs you can see after calling peek() weekdays remain the same. Example 3Now let’s have a quick look on a few examples of the above three functions. But when the queue is empty, remove() throws NoSuchElementException, while poll returns null. They work identically in normal circumstances. So it appears that remove() and poll() are exactly the same.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |