Java Deque remove() MethodThe remove() method of Java Deque interface is used to retrieve and remove the head of the deque. The method may differ by poll() method only in one case that it throws an exception if the given deque is empty. Specified by:remove in interface Queue<E> Syntax:Parameter:NA Return:The above method is used to return the head of the queue represented by the given deque. Throw:NoSuchElementException- If the given deque is empty. Example 1Test it NowOutput: The first character which has been popped is : W The remaining deque is given as : E L C O M E Example 2Test it NowOutput: The first string that has been popped is : Computer The remaining deque is given as : Programming Language Example 3Test it NowOutput: The first float value that has been popped is : 56.0 The remaining deque is given as : 24.9 58.0 Java Deque remove() MethodThe remove(Object o) method of Java Deque interface is used to remove the first occurrence of the given element from the deque. If the given deque has no element, then it remains unchanged. The above method returns true if the deque contains the specified element. Also, this method is equivalent to removeFirstOccurence(Object). Specified by:remove in interface Collection<E> Syntax:Parameter:The above method requires only one parameter:
Return:The above method is used to return true if the given element is removed. Throw:ClassCastException- If the class of the given element is incompatible with the given deque. NullPointerException- If the specified element is already null and the given deque does not allow the null elements. Example 1Test it NowOutput: The character is present in the deque : true The remaining deque is given as : W E L C O E Example 2Test it NowOutput: The float value is present in the deque : false The remaining deque is given as : 76.0 89.9 60.8 45.1 Example 3Test it NowOutput: The long value is present in the deque : true The remaining deque is given as : 67 50 22 Next TopicJava Deque |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India