VOOZH about

URL: https://www.geeksforgeeks.org/java/abstractqueue-clear-method-in-java-with-examples/

⇱ AbstractQueue clear() method in Java with examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

AbstractQueue clear() method in Java with examples

Last Updated : 11 Jul, 2025
The clear() method of AbstractQueue removes all of the elements from this queue. The queue will be empty after this call returns. Syntax:
public void clear()
Parameters: This method does not accept any parameters. Returns: The method does not returns anything. Below programs illustrate clear() method: Program 1:
Output:
AbstractQueue1 contains : [10, 20, 30, 40, 50]
AbstractQueue1 : []
Program 2:
Output:
AbstractQueue1 contains : [gopal, gfg, java]
AbstractQueue1 : []
Reference: https://docs.oracle.com/javase/8/docs/api/java/util/AbstractQueue.html#clear--
Comment