當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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–



相關用法


注:本文由純淨天空篩選整理自rupesh_rao大神的英文原創作品 AtomicLongArray toString() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。