当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。