Java AtomicIntegerArray toString()方法及示例
Java.util.concurrent.atomic.AtomicIntegerArray.toString() 是Java中的一个内置方法,它返回一个字符串,用文字表示AtomicIntegerArray的当前值。所得到的字符串是一个简明扼要、内容丰富的表示,容易让人阅读。它被用来轻松地将AtomicIntegerArray的内容打印成一个字符串对象。
语法
public String toString()
参数: 该函数不接受任何参数。
返回值: 该函数返回AtomicIntegerArray的当前值的字符串表示。
下面的程序说明了上述方法。
程序1 :
// Java program that demonstrates
// the toString() function
import java.util.concurrent.atomic.AtomicIntegerArray;
public class GFG {
public static void main(String args[])
{
// Initializing an array
int a[] = { 1, 2, 3, 4, 5 };
// Initializing an AtomicIntegerArray
// with array a
AtomicIntegerArray arr
= new AtomicIntegerArray(a);
// Displaying the AtomicIntegerArray
System.out.println("The array : "
+ arr);
// Displaying the string representation
// of AtomicIntegerArray
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.AtomicIntegerArray;
public class GFG {
public static void main(String args[])
{
// Initializing an array
int a[] = { 11, 12, 13, 14, 15 };
// Initializing an AtomicIntegerArray
// with array a
AtomicIntegerArray arr
= new AtomicIntegerArray(a);
// Displaying the AtomicIntegerArray
System.out.println("The array : " + arr);
// Displaying the string representation
// of AtomicIntegerArray
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/AtomicIntegerArray.html#toString-
极客教程