Java LinkedTransferQueue add() methodThe add() method of LinkedTransferQueue class is used to insert the specified element at the tail of the LinkedTransferQueue. The add() method overrides add in class AbstractQueue<E>. Syntax:Parameters:e - It is the element to add Specified By:The add() method of LinkedTransferQueue class is specified by :
Return:This method returns the Boolean value true. Throws:NullPointerException: This method will throw if the specified element is null. Example 1Test it NowOutput: After adding 1 to the queue : [1] After adding 2 to the queue : [1, 2] After adding 3 to the queue : [1, 2, 3] After adding 4 to the queue : [1, 2, 3, 4] After adding 5 to the queue : [1, 2, 3, 4, 5] Example 2Test it NowOutput: Queue : 718 8 18 119 Max number = 718 Min number = 8 Example 3Test it NowOutput: 1. Name = Jack 2. Name = Johnny 3. Name = Angelina 4. Name = Russell Example 4Test it NowOutput: Exception in thread "main" java.lang.NullPointerException at java.base/java.util.concurrent.LinkedTransferQueue.xfer(Unknown Source) at java.base/java.util.concurrent.LinkedTransferQueue.add(Unknown Source) at tests.LinkedTransferQueueAddExample4.main(LinkedTransferQueueAddExample4.java:5) Next TopicJava LinkedTransferQueue |
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