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:
import java.util.concurrent.LinkedTransferQueue;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws InterruptedException
{
LinkedTransferQueue<Integer> LTQ
= new LinkedTransferQueue<Integer>();
LTQ.add( 101 );
LTQ.add( 202 );
LTQ.add( 58 );
LTQ.add( 796 );
LTQ.add( 641 );
String st = LTQ.toString();
System.out.println( "String Representation: "
+ st);
}
}
|
Output:
String Representation: [101, 202, 58, 796, 641]
Program 2:
import java.util.concurrent.LinkedTransferQueue;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws InterruptedException
{
LinkedTransferQueue<String> LTQ
= new LinkedTransferQueue<String>();
LTQ.add( "GeeksforGeeks" );
LTQ.add( "Gfg" );
LTQ.add( "gfg" );
LTQ.add( "Geeks" );
LTQ.add( "geeks" );
String st = LTQ.toString();
System.out.println( "String Representation: "
+ st);
}
}
|
Output:
String Representation: [GeeksforGeeks, Gfg, gfg, Geeks, geeks]
Reference: https://docs.oracle.com/javase/9/docs/api/java/util/concurrent/LinkedTransferQueue.html#toString–
Feeling lost in the vast world of Backend Development? It's time for a change! Join our
Java Backend Development - Live Course and embark on an exciting journey to master backend development efficiently and on schedule.
What We Offer:
- Comprehensive Course
- Expert Guidance for Efficient Learning
- Hands-on Experience with Real-world Projects
- Proven Track Record with 100,000+ Successful Geeks
Last Updated :
08 Feb, 2019
Like Article
Save Article