AtomicReferenceArray類的toString()方法用於返回數組當前值的String表示形式,該方法用於將AtomicReferenceArray的內容表示為字符串
用法:
public String toString()
參數:此方法不接受任何內容。
返回值:此方法返回數組當前值的String表示形式。
以下示例程序旨在說明toString()方法:
程序1:
// Java program to demonstrate
// toString() method
import java.util.concurrent.atomic.*;
public class GFG {
public static void main(String[] args)
{
// create an atomic reference object.
AtomicReferenceArray<Integer> ref
= new AtomicReferenceArray<Integer>(5);
// set some value
ref.set(0, 234);
ref.set(1, 134);
ref.set(2, 325);
// print the toString() return
String toString = ref.toString();
System.out.println(
"String representation of"
+ " AtomicReferenceArray:\n"
+ toString);
}
}
輸出:
String representation of AtomicReferenceArray: [234, 134, 325, null, null]
程序2:
// Java program to demonstrate
// toString() method
import java.util.concurrent.atomic.*;
public class GFG {
public static void main(String[] args)
{
// create a array of Strings
String[] names
= { "AMAN", "AMAR", "SURAJ" };
// create an atomic reference object.
AtomicReferenceArray<String> ref
= new AtomicReferenceArray<String>(names);
// print the toString() return
String toString = ref.toString();
System.out.println(
"String representation of"
+ " AtomicReferenceArray:\n"
+ toString);
}
}
輸出:
String representation of AtomicReferenceArray: [AMAN, AMAR, SURAJ]
相關用法
- Java AtomicReferenceArray get()用法及代碼示例
- Java AtomicReferenceArray set()用法及代碼示例
- Java AtomicReferenceArray getAndAccumulate()用法及代碼示例
- Java AtomicReferenceArray setPlain()用法及代碼示例
- Java AtomicReferenceArray accumulateAndGet()用法及代碼示例
- Java AtomicReferenceArray getPlain()用法及代碼示例
- Java AtomicReferenceArray weakCompareAndSetPlain()用法及代碼示例
- Java AtomicReferenceArray lazySet()用法及代碼示例
- Java AtomicReferenceArray compareAndSet()用法及代碼示例
- Java AtomicReferenceArray compareAndExchangeRelease()用法及代碼示例
- Java AtomicReferenceArray compareAndExchange()用法及代碼示例
- Java AtomicReferenceArray compareAndExchangeAcquire()用法及代碼示例
- Java AtomicReferenceArray getAndSet()用法及代碼示例
- Java AtomicReferenceArray getAcquire()用法及代碼示例
- Java AtomicReferenceArray setRelease()用法及代碼示例
注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 AtomicReferenceArray toString() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。