LinkedTransferQueue toString() method in Java with Examples
The toString() method of java.util.concurrent.LinkedTransferQueue is an in-built function is Java which is used to return the string representation of the collection. The String representation consists of the elements of the collection enclosed in “[]” and separated by “, “. The order of elements in the spring representation appear in the order of their iteration.
Syntax:
public String toString ()
Parameters: This method do not accepts any parameter.
Return Value: This method returns a string representation of the collection containing the elements in the same order.
Exceptions: No Exceptions are present.
Below program illustrates the toString() function of LinkedTransferQueue class :
Program 1:
// Java Program Demonstrate LinkedTransferQueue // toString() method import java.util.concurrent.LinkedTransferQueue; import java.util.*; public class GFG { public static void main(String[] args) throws InterruptedException { // create object of LinkedTransferQueue // using LinkedTransferQueue() constructor LinkedTransferQueue<Integer> LTQ = new LinkedTransferQueue<Integer>(); // Add numbers to end of LinkedTransferQueue LTQ.add(101); LTQ.add(202); LTQ.add(58); LTQ.add(796); LTQ.add(641); // Store the string representation of the // collection String object st String st = LTQ.toString(); // Print String representation System.out.println("String Representation: " + st); } } |
String Representation: [101, 202, 58, 796, 641]
Program 2:
// Java Program Demonstrate LinkedTransferQueue // toString() method import java.util.concurrent.LinkedTransferQueue; import java.util.*; public class GFG { public static void main(String[] args) throws InterruptedException { // create object of LinkedTransferQueue // using LinkedTransferQueue() constructor LinkedTransferQueue<String> LTQ = new LinkedTransferQueue<String>(); // Add numbers to end of LinkedTransferQueue LTQ.add("GeeksforGeeks"); LTQ.add("Gfg"); LTQ.add("gfg"); LTQ.add("Geeks"); LTQ.add("geeks"); // Store the string representation of the // collection String object st String st = LTQ.toString(); // Print String representation System.out.println("String Representation: " + st); } } |
String Representation: [GeeksforGeeks, Gfg, gfg, Geeks, geeks]
Reference: https://docs.oracle.com/javase/9/docs/api/java/util/concurrent/LinkedTransferQueue.html#toString–
Recommended Posts:
- LinkedTransferQueue getWaitingConsumerCount() method in Java with Examples
- LinkedTransferQueue removeIf() method in Java with Examples
- LinkedTransferQueue toArray() method in Java with Examples
- LinkedTransferQueue retainAll() method in Java with Examples
- LinkedTransferQueue forEach() method in Java with Examples
- LinkedTransferQueue removeAll() method in Java with Examples
- LinkedTransferQueue tryTransfer() method in Java with Examples
- LinkedTransferQueue transfer() method in Java with Examples
- LinkedTransferQueue remainingCapacity() method in Java with Examples
- LocalTime toString() method in Java with Examples
- DigestOutputStream.toString() method in Java with Examples
- Modifiers toString() method in Java with Examples
- ChronoLocalDateTime toString() method in Java with Examples
- ChronoZonedDateTime toString() method in Java with Examples
- LongAccumulator toString() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



