Java AtomicLongArray toString()方法及示例
Java.util.concurrent.atomic.AtomicLongArray.toString() 是Java中的一个内置方法,它返回一个字符串,用文字表示AtomicLongArray的当前值。所得到的字符串是一个简明的、信息量大的表示,很容易让人阅读。它被用来轻松地将AtomicLongArray的内容打印成一个字符串对象。
语法
public String toString()
参数: 该函数不接受任何参数。
返回值: 该函数返回AtomicLongArray当前值的字符串表示。
下面的程序说明了上述方法。
程序1 :
// Java program that demonstrates
// the toString() function
import java.util.concurrent.atomic.AtomicLongArray;
public class GFG {
public static void main(String args[])
{
// Initializing an array
long a[] = { 1, 2, 3, 4, 5 };
// Initializing an AtomicLongArray
// with array a
AtomicLongArray arr
= new AtomicLongArray(a);
// Displaying the AtomicLongArray
System.out.println("The array : "
+ arr);
// Displaying the string representation
// of AtomicLongArray
System.out.println("The string representation"
+ " of the array: "
+ arr.toString());
}
}
输出。
The array : [1, 2, 3, 4, 5]
The string representation of the array: [1, 2, 3, 4, 5]
程序2
// Java program that demonstrates
// the toString() function
import java.util.concurrent.atomic.AtomicLongArray;
public class GFG {
public static void main(String args[])
{
// Initializing an array
long a[] = { 11, 12, 13, 14, 15 };
// Initializing an AtomicLongArray
// with array a
AtomicLongArray arr
= new AtomicLongArray(a);
// Displaying the AtomicLongArray
System.out.println("The array : " + arr);
// Displaying the string representation
// of AtomicLongArray
System.out.println("The string representation"
+ " of the array: "
+ arr.toString());
}
}
输出。
The array : [11, 12, 13, 14, 15]
The string representation of the array: [11, 12, 13, 14, 15]
参考资料: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicLongArray.html#toString-