Java中的 LinkedBlockingDeque toString() 方法
LinkedBlockingDeque的toString()方法返回此集合的字符串表示形式。字符串表示由集合元素的列表组成,按其迭代器返回的顺序排列,用方括号(“[]”)括起来。相邻元素由字符“、” (逗号和空格)分隔。通过 String.valueOf(Object) 将元素转换为字符串。
句法:
public String toString()
参数:此方法不接受任何参数。
返回:此方法返回此集合的字符串表示形式。
下面的程序说明了 LinkedBlockingDeque 的toString()方法:
方案一:
// Java Program Demonstrate toString()
// method of LinkedBlockingDeque
import java.util.concurrent.LinkedBlockingDeque;
import java.util.*;
public class GFG {
public static void main(String[] args)
{
// create object of LinkedBlockingDeque
LinkedBlockingDeque LBD
= new LinkedBlockingDeque();
// Add numbers to end of LinkedBlockingDeque
LBD.add(7855642);
LBD.add(35658786);
LBD.add(5278367);
LBD.add(74381793);
// Print the queue
System.out.println("Linked Blocking Deque: " + LBD);
System.out.println("LBD in string " + LBD.toString());
}
}
输出:
Linked Blocking Deque: [7855642, 35658786, 5278367, 74381793]
LBD in string [7855642, 35658786, 5278367, 74381793]
方案二:
// Java Program Demonstrate toString()
// method of LinkedBlockingDeque
import java.util.concurrent.LinkedBlockingDeque;
import java.util.*;
public class GFG {
public static void main(String[] args)
{
// create object of LinkedBlockingDeque
LinkedBlockingDeque LBD
= new LinkedBlockingDeque();
// Add numbers to end of LinkedBlockingDeque
LBD.add("geeks");
LBD.add("sudo");
LBD.add("gate");
LBD.add("gopal");
// Print the queue
System.out.println("Linked Blocking Deque: " + LBD);
System.out.println("LBD in string " + LBD.toString());
}
}
输出:
Linked Blocking Deque: [geeks, sudo, gate, gopal]
LBD in string [geeks, sudo, gate, gopal]
参考: https: Java/util/concurrent/LinkedBlockingDeque.html#toString–