LinkedTransferQueue add() method in Java Last Updated : 14 Sep, 2018 Comments Improve Suggest changes Like Article Like Report The add() method of java.util.concurrent.LinkedTransferQueue is an in-built function in Java which is used to insert an element in this queue. Syntax: LinkedTransferQueue.add(E e) Parameters: The function accepts a single parameter e i.e. the element to be inserted. Return Value: The function returns a boolean value. Exception: The function throws NullPointerException when the specified element is Null. Below programs illustrate the use of java.util.concurrent.LinkedTransferQueue.add() : Program 1: Inserting Integers in the queue. Java // Java Program Demonstrate add() // method of LinkedTransferQueue import java.util.concurrent.*; class LinkedTransferQueueAddExample1 { public static void main(String[] args) { // Initializing the queue LinkedTransferQueue<Integer> queue = new LinkedTransferQueue<Integer>(); // Adding elements to this queue for (int i = 10; i <= 15; i++) queue.add(i); // Printing the elements of the queue System.out.println("The elements in the queue are:"); for (Integer i : queue) System.out.print(i + " "); } } Output: The elements in the queue are: 10 11 12 13 14 15 Program 2: Adding String in the queue. Java // Java Program Demonstrate add() // method of LinkedTransferQueue import java.util.concurrent.*; class LinkedTransferQueueAddExample2 { public static void main(String[] args) { // Initializing the queue LinkedTransferQueue<String> queue = new LinkedTransferQueue<String>(); // Adding elements to this queue queue.add("a"); queue.add("b"); queue.add("c"); queue.add("d"); queue.add("e"); // Printing the elements of the queue System.out.println("The elements in the queue are:"); for (String i : queue) System.out.print(i + " "); } } Output: The elements in the queue are: a b c d e Program 3: To demonstrate NullPointerException Java // Java Program Demonstrate add() // method of LinkedTransferQueue import java.util.concurrent.*; class LinkedTransferQueueAddExample2 { public static void main(String[] args) { // Initializing the queue LinkedTransferQueue<String> queue = new LinkedTransferQueue<String>(); try { // Adding null to this queue queue.add(null); } catch (Exception e) { System.out.println("Exception: " + e); } } } Output: Exception: java.lang.NullPointerException Reference: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/LinkedTransferQueue.html#add(E) Comment More infoAdvertise with us R rupesh_rao Follow Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions Java-LinkedTransferQueue +2 More Practice Tags : JavaJava-CollectionsMisc Explore BasicsIntroduction to Java4 min readJava Programming Basics9 min readJava Methods7 min readAccess Modifiers in Java6 min readArrays in Java9 min readJava Strings8 min readRegular Expressions in Java7 min readOOPs & InterfacesClasses and Objects in Java10 min readJava Constructors10 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages7 min readJava Interface11 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java6 min readIterator in Java5 min readJava Comparator Interface6 min readException HandlingJava Exception Handling8 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial15+ min readSynchronization in Java10 min readFile Handling in Java5 min readJava Method References9 min readJava 8 Stream Tutorial15+ min readJava Networking15+ min readJDBC Tutorial12 min readJava Memory Management4 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples8 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions7 min readJava Quiz | Level Up Your Java Skills1 min readTop 50 Java Project Ideas For Beginners and Advanced [Update 2025]15+ min read Like